Docker Images #
Docker images are templates for instances of Docker containers.
Creating images #
Dockerfile #
Every image created starts with a Dockerfile that specifies what goes into the image and how to configure things.
Including specifications for:
- Packages to be installed
- Dependencies
- Where to copy source code from
- Specifications for entrypoints
- …
For more details, check out the page on Dockerfile
Images are built in a layered manner, going from top to bottom of the Dockerfile. Each layer only builds up on the previous layer, allowing for images to be very lean.
To see the layers, check the history:
docker history <Docker app>
Builds can be initiated at intermediate layers.
Build #
Once the Dockerfile is configured, build the image with tag, when you’re in the location with the Dockerfile:
docker build .
^ This basically reads as, “Docker, build the local image here”.
The Docker image can also be tagged:
docker build Dockerfile -t <Docker app tag>
^ This creates a local image with a specified name (tag).
Check #
Once the image is built, check for it with:
docker images
And you should see the just build image.
Build Process #
Rebuilds happen at intermediate layers where things break. This allows for Docker images to be built in a fast and lean manner.
Sharing #
To put the built image in Dockerhub, run:
docker push <docker app name>
A common naming and sharing configuration is
Run #
For details on how to run Docker images, check out Docker run.
Stop #
To stop Docker images that are running:
docker ps # to get a listing of running images
docker stop <Docker app name or id>
Note that stopping a Docker container only stops it; it doesn’t remove it.
You can verify it’s not truly removed with:
docker ps -a
^ Shows Docker iamges that are still there, stopped, but not yet removed.
Start #
For Docker images that are stopped but still there, they can be started with:
docker start <container name or id>
Remove #
To remove a Docker container (and not just stop it):
docker rm <container name or id>
To fully remove a Docker image so it no longer exists:
docker images # verifies that the image still exists
docker rmi <image name or id>
If you need to force remove the Docker image:
docker rmi -f <image name or id>