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 imagemynginx:latest
We give the image a name ofmynginx
and tag islatest