Building Images Interactively Docker Fundamentals d7590d1 136 © 2015 Docker Inc
Create a new container and make some changes Start an Ubuntu container: $ docker run -it ubuntu [email protected]<yourContainerId>:#/ Run the command apt-get update to refresh the list of packages available to install. Then run the command apt-get install figlet to install the program we are interested in. [email protected]<yourContainerId>:#/ apt-get update && apt-get install figlet .... OUTPUT OF APT-GET COMMANDS .... Building Images Interactively Docker Fundamentals d7590d1 137 © 2015 Docker Inc
Inspect the changes Type exit at the container prompt to leave the interactive session. Now let's run docker diff to see the difference between the base image and our container. $ docker diff <yourContainerId> C /root A /root/.bash_history C /tmp C /usr C /usr/bin A /usr/bin/figlet ... Building Images Interactively Docker Fundamentals d7590d1 138 © 2015 Docker Inc
Docker tracks filesystem changes As explained before: • An image is read-only. • When we make changes, they happen in a copy of the image. • Docker can show the difference between the image, and its copy. • For performance, Docker uses copy-on-write systems. (i.e. starting a container based on a big image doesn't incur a huge copy.) Building Images Interactively Docker Fundamentals d7590d1 139 © 2015 Docker Inc
Commit and run your image The docker commit command will create a new layer with those changes, and a new image using this new layer. $ docker commit <yourContainerId> <newImageId> The output of the docker commit command will be the ID for your newly created image. We can run this image: $ docker run -it <newImageId> [email protected]:/# figlet hello _ _ _ | |__ ___| | | ___ | '_ \ / _ \ | |/ _ \ | | | | __/ | | (_) | |_| |_|\___|_|_|\___/ Building Images Interactively Docker Fundamentals d7590d1 140 © 2015 Docker Inc
Tagging images Referring to an image by its ID is not convenient. Let's tag it instead. We can use the tag command: $ docker tag <newImageId> figlet But we can also specify the tag as an extra argument to commit : $ docker commit <containerId> figlet And then run it using its tag: $ docker run -it figlet Building Images Interactively Docker Fundamentals d7590d1 141 © 2015 Docker Inc
What's next? Manual process = bad. Automated process = good. In the next chapter, we will learn how to automate the build process by writing a Dockerfile . Building Images Interactively Docker Fundamentals d7590d1 142 © 2015 Docker Inc
Building Docker images Building Docker images Docker Fundamentals d7590d1 143 © 2015 Docker Inc
Lesson 9: Building Images With A Dockerfile Objectives We will build a container image automatically, with a Dockerfile . At the end of this lesson, you will be able to: • Write a Dockerfile . • Build an image from a Dockerfile . Building Docker images Docker Fundamentals d7590d1 144 © 2015 Docker Inc
Dockerfile overview • A Dockerfile is a build recipe for a Docker image.
You've reached the end of your free preview.
Want to read all 354 pages?
- Fall '17