Containers
# Create and run a container from an image, with a custom name:
docker run --name <container_name> <image_name>
# Run a container with and publish a container’s port(s) to the host.
docker run -p <host_port>:<container_port> <image_name>
# Run a container in the background
docker run -d <image_name>
| Example | Description |
|---|---|
docker ps | List running containers |
docker ps -a | List all containers |
docker exec -it <container> bash | Connecting to container |
docker logs <container> | Shows container’s console log |
docker start/stop <container> | Start or stop a container |
docker kill <container> | Kill a container |
docker restart <container> | Restart a container |
docker rm <container> | Remove a container |
Images
# Build an Image from a Dockerfile
docker build -t <image_name>
# Build an Image from a Dockerfile without the cache
docker build -t <image_name> . –no-cache
# List local images
docker images
# Delete an Image
docker rmi <image_name>
# Remove all unused images
docker image prune
| Example | Description |
|---|---|
docker ps | List running containers |
docker ps -a | List all containers |
docker exec -it <container> bash | Connecting to container |
docker logs <container> | Shows container’s console log |
docker start/stop <container> | Start or stop a container |
docker kill <container> | Kill a container |
docker restart <container> | Restart a container |
docker rm <container> | Remove a container |