Intro Docker Commands
Quick way to get started with Docker post install
Play this article
Installing docker is easy and well documented at Docker Docs. Here are some quick commands you can use to get started with Docker containers.
Getting Started
- Docker version:
docker --version
- Check that Docker is working by running the hello-world container:
docker run hello-world
- List all images that are locally stored:
docker image ls
Starting a Container
- Start a Docker container
docker container run --name <Name of container>
- Run docker container in interactive mode
docker run -it --name my-container image_id_here
- List Docker containers (running and stopped):
docker container ls --all
- Start container and map a local OS port to docker port
docker run -d -p 80:80 nginx
- Start a container and map a service port to a random port
docker run -d -P nginx
Image Management
- Pull an image from Docker Hub:
docker pull <user_name>/<repo_name>:<version_v1>
- Push an image to Docker Hub:
docker push <user_name>/<repo_name>:<version>
- Tag a container
docker tag <image_id> peteawalk/<name_of_repo>:v1
- Pull an image from Docker Hub registry:
docker pull alpine:3.4
- Delete an image from the local image store:
docker image rm alpine:3.4
Container Management
- Look for all containers running or exited:
peterconqueso@pop-os:~$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8a9c5b104898 40afe17d4955 "/sbin/tini -- /usr/…" 24 hours ago Exited (129) 23 hours ago jenkins
- Access Docker container with bash shell:
docker exec -it <Name of container> /bin/bash
- Run a quick command (file system sizing) in container without accessing container:
docker exec -it <Name of container> df -hP
- Look at container information, such as state, image, config
docker container inspect <container_id>
- Grab docker container IP Addres
docker container inspect <container_id> | grep IPAdd
- Remove unused containers
docker container rm <container_id>
- Remove all stopped and exited containers AND free up disk space:
docker container prune