This will be a walk through of a very basic Docker setup, from pulling down a base image to making a simple change and commit. I'm going to assume you already know what Docker is.
Searching Docker images
Let's pull down a Docker base image.
docker search command will allow you to search for images. You will get an output of different images, both official and unofficial. These are hosted on Docker's own hub website. For this example I will search for an 'Ubuntu' base image.
docker search ubuntu
Pulling and running
Pulling the image you want is a simple case of typing:
docker pull ubuntu
Once you have pulled this down, you can create a container based on your image. In this example I will use an interactive shell to launch into my new container based on my base ubuntu image. The container will stop immediately unless you have decided to run an application as a daemon.
docker run -i -t ubuntu bash
-t flag assigns a pseudo-tty or terminal inside our new container and the
-i flag allows us to make an interactive connection by grabbing the standard in (STDIN) of the container. Basically allowing us to enter the container and input whatever command you want. You can also create a daemonized container which would run a process of your choosing in the background of a container, the example I've linked shows you how to echo 'hello world' in a loop.
If you end the shell process, your container will be stopped immediatly. This is normal behaviour.
If you run through an interactive shell, you will see your container id is represented as the
hostname in this shell. You can also see all your container id's by running
docker ps -l once exited.
You can port foward for a container using the
Used in full context with the run command would look something like this.
docker run -i -t -p 5555:80 ubuntu bash
You can also forward to a specific interface too.
docker run -i -t -p 127.0.0.1:5555:80 ubuntu bash
Making changes and commiting
Following on from how we launched into an interactive terminal, we can make and save changes to this container.
Let's make a directory as a simple example inside your interactive container.
exit from your interactive terminal (which will stop the container).
If you run
docker diff <container_id> you will notice that your directory addition has been made.
Commiting this change is a simple case of running
docker commit <container_id> <new_image_name>. Your changes will be stored as a new image, and of course you'll be able to spin up a new container from your saved image. This could then be pushed up to the Docker hub for others to use.