Run a Container
docker runCreates a container from an image and starts it. Add -d to run it in the background.
Commands for containers, images, volumes and Compose projects. Every item below is clearly marked as a shortcut, command, or syntax reference.
docker runCreates a container from an image and starts it. Add -d to run it in the background.
docker psShows the containers that are currently up, with their ID, name, image, status and ports.
docker exec -it CONTAINER bashRuns a command inside a container that is already up, such as a bash prompt.
docker build -t NAME .Builds an image from the Dockerfile in the current folder.
docker compose upBuilds, creates and starts every service in your compose file.
docker ps -aShows running containers plus the ones that have stopped.
docker stopSends a shutdown request and stops a running container.
docker logs CONTAINERPrints the output a container has written. Add -f to keep watching new lines.
Creates a container from an image and starts it. Add -d to run it in the background.
docker runShows the containers that are currently up, with their ID, name, image, status and ports.
docker psRuns a command inside a container that is already up, such as a bash prompt.
docker exec -it CONTAINER bashBuilds an image from the Dockerfile in the current folder.
docker build -t NAME .Builds, creates and starts every service in your compose file.
docker compose upShows running containers plus the ones that have stopped.
docker ps -aSends a shutdown request and stops a running container.
docker stopPrints the output a container has written. Add -f to keep watching new lines.
docker logs CONTAINERShows the images stored on your machine.
docker imagesDownloads an image from a registry to your machine.
docker pull IMAGEStarts the services and hands your terminal back.
docker compose up -dStops and removes the containers, network and other resources a compose run created.
docker compose downOpens a terminal inside a new container so you can type commands in it.
docker run -it ubuntu bashStarts a container that already exists but is stopped.
docker startStops and starts a container in one step.
docker restartDeletes a container you no longer need.
docker rmKeeps the log open and prints new lines as they arrive.
docker logs -f CONTAINERUploads an image to a registry so others can pull it.
docker push IMAGEPrints the full configuration of a container as JSON.
docker inspect CONTAINERDeletes an image from your machine.
docker rmi IMAGERemoves stopped containers, unused networks, dangling images and build cache.
docker system prunePrints the output of every service in the project.
docker compose logsEnds a container immediately with no chance to clean up.
docker killClears out every container that is not running.
docker container pruneMoves a file between your machine and a container.
docker cp SOURCE CONTAINER:DESTINATIONGives an image another name or version, ready for pushing.
docker tag SOURCE TARGETReports how much space images, containers and volumes are taking.
docker system dfLogs you in so you can push images to a registry.
docker loginShows the services running for the current compose project.
docker compose psBuilds the images your compose file asks for.
docker compose buildConnects your terminal to a running container's main process.
docker attach CONTAINERPrints details about your Docker installation, hosts and resource totals.
docker infoPrints the client and server version numbers.
docker versionShows the volumes Docker manages on your machine.
docker volume lsMakes a named volume for persistent data.
docker volume create NAMEShows the Docker networks on your machine.
docker network lsMakes an isolated network so containers can reach each other by name.
docker network create NAMEDownloads the images the compose services depend on.
docker compose pullRestarts the services defined in the compose file.
docker compose restartLists the processes running inside a container, like top.
docker top CONTAINERChanges the name of a container.
docker rename OLD NEWTurns the current state of a container into a new image.
docker commit CONTAINER IMAGELists the build steps an image was made from, newest first.
docker history IMAGEExports an image so you can move it without a registry.
docker save -o FILE.tar IMAGEImports an image that was saved with docker save.
docker load -i FILE.tarDeletes a volume and the data in it.
docker volume rm NAMEJoins a running container to an existing network.
docker network connect NETWORK CONTAINERShows the endpoints your Docker client can talk to.
docker context lsPoints your Docker client at another endpoint until you switch back.
docker context use NAMEBlocks until the container exits, then prints its exit code.
docker wait CONTAINERCommon Docker commands include Run a Container (docker run), List Running Containers (docker ps), Open a Shell in a Running Container (docker exec -it CONTAINER bash), Build an Image (docker build -t NAME .), Start a Compose Project (docker compose up).
Type each command in the terminal or command-line interface used by Docker.
Read its reference page and the linked documentation for prerequisites and placeholders. Check the current directory and target before running commands that change or delete data.