Below are some of the common commands and examples of how to work with Docker.
Search for a Docker Image
docker search <image name>
Example of searching for a Docker Image:
docker search redis
Run and/or Install a Docker Image
docker run <image name>
Example of running and/or installing a Docker Image:
docker run redis
Run and/or Install a Docker Image in the Background
docker run -d <image name>
Example of running and/or installing a Docker Image in the Background:
docker run -d redis
List All Running Containers
docker ps
Example Output of Listing All Running Docker Containers:
View IP Address and Details for a Running Container
docker inspect <friendly name | container id>
Example Output of Inspecting the Details for a Running Docker Container:
View Logs for a Running Container
docker logs <friendly name | container id>
Example Output of Logs for a Running Docker Container:
Defining a Name and Port for a Docker Container
docker run -d --name <any name you want> -p <port mapping> <image name>
Example of Defining a Name and Port for a Docker Container:
docker run -d --name redisStore -p 6379:6379 redis
Defining a Dynamic Port for a Docker Container
docker run -d --name <any name you want> -p <port> <image name>
Example of Defining a Name and Port for a Docker Container:
docker run -d --name redisStoreTwo -p 6379 redis
Persisting Data in a Redis Data Store
docker run -d --name <any name you want> -p <port> -v /opt/docker/data/redis:/data <image name>
Example of Defining a Name and Port for a Docker Container (requires special system permissions):
docker run -d --name redisPersisted -p 6379 -v /opt/docker/data/redis:/data redis
Running a Bash Command with a Docker Container
docker run <os name> <command>
Example of Running a Bash Command with a Docker Container
docker run ubuntu ls
Opening Up a Bash Shell Session with a Docker Container
docker run -it <os name> bash
Example of Opening Up a Bash Shell Session with a Docker Container
docker run -it ubuntu bash