Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

README.md

Dockerfile

Dockerfile is a way to create new container images.

You can think of it as a DSL for building Docker images.

FROM - The Base Image

Create a new file called Dockerfile and add the following line

FROM ubuntu:16.04

Now build it. Note the successfully built image id

docker build .

Now run it

docker run -it <image id>

CMD - What program should I run?

Modify your Dockerfile to look like this

FROM ubuntu:16.04

CMD echo "Hello, World!"

Now build it. This time we will name it

docker build -t hello .

Did you see the image ids? How many images did we create?

Now run it by name

docker run hello

We will then see that "Hello, World!" is executed and returned to the host.

We could also

# Run the container in the background
docker run -d hello
# Observe we get a container id

# Look at the container's logs
docker logs <container id>

And see that "Hello, World!" is definitely run inside the container.

RUN - Execute a command at build time

The run command will allow us to add build steps to our container build.

In this case we are installing the python tools

FROM ubuntu:16.04

RUN apt-get update && apt-get install -y python-dev

CMD python --version

Let's add another command after that long running command and see how caching works

FROM ubuntu:16.04

RUN apt-get update && apt-get install -y python-dev

RUN echo "some other command"

CMD python --version

Note the cached result of the previous command made things a lot quicker

Check out the full Dockerfile reference