Docker로 PHP 올리기

@ZungTa · 2021-09-07 화요일 · 1 min read

References

일단 해당 php 프로젝트가 있는 폴더에서 Dockerfile을 생성한다.

FROM ubuntu:18.04

# Avoiding user interaction with tzdata
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update
RUN apt-get install -y apache2 # install Apache web server (Only 'yes')
RUN apt-get install -y software-properties-common # php 5.6(이전버전) 설치를 위해
RUN add-apt-repository ppa:ondrej/php # For Installing PHP 5.6
RUN apt-get update
RUN apt-get install -y php5.6

EXPOSE 80

CMD ["apachectl", "-D", "FOREGROUND"]

그리고 docker build를 진행한다.

docker build . -t my-php

그럼 도커 이미지가 만들어졌다.

그 이미지를 이용해서 컨테이너를 올리자.

docker run -d --name [name] -p 8080:80 -v /home/ubuntu/example/html:/var/www/html example

성공적으로 컨테이너가 실행되었으면 http://localhost:8080 에 접속해보면 된다.

References

@ZungTa
I'm a backend developer
© ZungTa Devlog, Built with Gatsby