Skip to content

Docker Image Container Management from the Command Line

Cecilia Wong edited this page Apr 29, 2024 · 4 revisions

This section illustrates common use cases with a local Docker instance.

Image management

List all existing images for this project

docker images python-webservice-demo*

This command assumes that all images were either created with the command docker compose up --build -d or explicitly assigned the name python-webservice-demo upon creation by docker build.

Create new image

Run the following command at the project root:

docker build -t python-webservice-demo:test .

An image on this project with name python-webservice-demo and tag test is created.

Delete an image

docker image rm python-webservice-demo:test

This command deletes the image with name python-webservice-demo and tag test.

Rename an image

The following example renames the image python-webservice-demo:test to webservice-new-image:latest.

  1. Create a new target image from the source image.
docker image tag python-webservice-demo:test webservice-new-image:latest
  1. Delete the source image (see above for the command).

Container management

List all existing containers

docker container ls --all

Create a new container

docker container create -p 5000:5000 -e LOG_LEVEL=DEBUG --name python-ws-demo python-webservice-demo:test

This command publishes the container from image python-webservice-demo:test to port 5000, setting environment variable LOG_LEVEL to DEBUG.

Start a container

docker start python-ws-demo

This command starts the container with name python-ws-demo.

Stop a container

docker stop python-ws-demo

This command stops the container with name python-ws-demo.

Delete a container

docker container rm python-ws-demo

This command deletes the container with name python-ws-demo.

References

Clone this wiki locally