subraun
3/30/2016 - 5:03 PM

Simple Dockerfile example

Simple Dockerfile example

###
# cd into directory containing 'Dockerfile'

### dockerfile

[ec2-user ecs-demo-php-simple-app]$ cat Dockerfile
FROM ubuntu:12.04

# Install dependencies
RUN apt-get update -y
RUN apt-get install -y git curl apache2 php5 libapache2-mod-php5 php5-mcrypt php5-mysql

# Install app
RUN rm -rf /var/www/*
ADD src /var/www

# Configure apache
RUN a2enmod rewrite
RUN chown -R www-data:www-data /var/www
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2

EXPOSE 80

CMD ["/usr/sbin/apache2", "-D",  "FOREGROUND"]

### build image from dockerfile
docker build -t my-dockerhub-username/amazon-ecs-sample .

### check image has been built
$ docker images
REPOSITORY                                TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
my-dockerhub-username/amazon-ecs-sample   latest              43c52559a0a1        12 minutes ago      258.1 MB
ubuntu                                    12.04               78cef618c77e        3 weeks ago         133.7 MB


### run container and map exposed port 80 to port 80 of host
docker run -p 80:80 my-dockerhub-username/amazon-ecs-sample
# The container can be stopped by hitting Ctrl-C

### Upload container into Docker Hub account
# Log in to your Docker Hub account
docker login
# Verify that you have logged in correctly (You should see "Username: my-dockerhub-username" in the output)
docker info
# Push the image
docker push my-dockerhub-username/amazon-ecs-sample