Docker Quickstart

This is a quick and dirty tutorial on how to get started with Docker, running in Docker machine on an OS X machine. This assumes you’ve already setup a Docker Machine.

So, basically:

docker pull ubuntu

(to get the latest Ubuntu images)

Then, in a Dockerfile:

FROM ubuntu:latest

RUN apt-get -y update && apt-get -y install apache2

# Manually set up the apache environment variables
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid

EXPOSE 80

#CMD service apache2 start
CMD /usr/sbin/apache2ctl -D FOREGROUND

“Build” the image with:

docker build -t wordpresstest .

Get the image ID with:

docker images

Run the image with:

docker run -p 8080:80  [ID OF IMAGE HERE]

(Optional) Log into the container instance with:

docker exec -it [ID OF RUNNING CONTAINER HERE] bash

Get the docker machine IP address with:

docker-machine ip firsttest

Open up http://%5BIP OF DOCKER MACHINE]:8080/

There we go! First running Docker container. You can stop the container with:

docker stop [ID OF RUNNING CONTAINER HERE]

You can now verify that the above URL is no longer displaying, which confirms that the web page was being served up by the container.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.