Dockerfile is a way to create new container images.
You can think of it as a DSL for building Docker images.
Create a new file called Dockerfile and add the following line
FROM ubuntu:16.04Now build it. Note the successfully built image id
docker build .Now run it
docker run -it <image id>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 helloWe 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.
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 --versionLet'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 --versionNote the cached result of the previous command made things a lot quicker
Check out the full Dockerfile reference