June 12, 2018

Docker Images

^ Ad space to help offset hosting costs :D

We can see how to grab an image from Docker hub. We'll use a "base image" in our projects here of Ubuntu 18.04.

We can just run a container using that image name. If that image does not exist locally, Docker will check Docker Hub (hub.docker.com) to see if that image exists. If it does exist, Docker "pulls" (downloads) that image and makes it available locally.

docker run --rm -it \
    ubuntu:18.04 \
    bash

This starts up a new container from Ubuntu 18.04 and runs bash inside of it.

Making our own images

Inside the container, we can make some changes:

apt-get update
apt-get install -y nginx

Then we can inspect that container to see the changes:

# From outside the container

docker diff <container-id-here>

This shows all the changes to the container (files added, modified, deleted).

We can then commit those changes to make a new image from that container and its changes!

docker commit -a "Chris Fidao" \
    -m "Nginx installed" \
    <container-id-here> \
    mynginx:latest

Here we commit changes made to the running container:

  • -a Author is set to "Chris Fidao"
  • -m "Nginx installed" We give it a commit message (similar to git!)
  • <container-id-here> We pass it the container from which to make a new image
  • mynginx:latest We give the image a name of mynginx and tag is latest

Looking for a deeper dive into Docker?

Sign up here to get a preview of the Shipping Docker course! Learn how to integrate Docker into your applications and develop a workflow to make using Docker a breeze!

All Topics