
Once you start the build, you'll see it churn away for a while installing things, and when it completes, you'll have a brand new image. Also not the final ".", which tells Docker to use the Dockerfile in the current directory. The "-t" flag adds a tag to the image so that it gets a nice repository name and tag.


Once we have a Dockerfile itself, we can build an image using docker build, like this: $ docker build -t "simple_flask:dockerfile".
Docker run image example install#
RUN apt-get install -y python python-pip wgetĪs you can see, it's pretty straightforward: we start from "ubuntu:latest," install dependencies with the RUN command, add our code file with the ADD command, and then set the default directory for when the container starts. Let's take a look at the example we went through in our overview chapter and condense it into a Dockerfile: # Perhaps the best way to understand a Dockerfile is to dive into an example. Example of building an image from a Dockerfile Each line in the Dockerfile will correspond to a layer in the images' commit history. The build command results in a new image that you can start using docker run, just like any other image. The format for this command is: docker build PATH | URL |. Once you've created a Dockerfile and added all your instructions, you can use it to build an image using the docker build command. Set the default working directory for the container Sets the default user within the containerĬreates a shared volume that can be shared among containers or by the host machine This is mandatory and must be the first command in the file.Īn optional value for the maintainer of the scriptĪ command that is triggered when the image in the Dcokerfile is used as a base for another imageĮxecutes a command and save the result as a new layer Sets an environment variable in the new container The command that runs when the container starts The following table summarizes the instructions many of these options map directly to option in the "docker run" command: CommandĬopies a file from the host system onto the container Overall, a Dockerfile is much more stripped down than the IA tools, consisting of a single file with a DSL that has a handful of instructions. A Dockerfile is similar in concept to the recipes and manifests found in infrastructure automation (IA) tools like Chef or Puppet. Rather than just running commands and adding files with tools like wget, we'll put our instructions in a special file called the Dockerfile. In this chapter, we'll look at a more robust way to build an image.

In the walkthrough, we took a very simple approach of just starting a container interactively, running the commands we wanted (like "apt-get install" and "pip install"), and then committing the container into a new image.

