Skip to content

Instantly share code, notes, and snippets.

@saisurya-kat
Last active April 29, 2017 09:56
Show Gist options
  • Save saisurya-kat/3e4fe2d1cf1052c4ad209f738d265ad9 to your computer and use it in GitHub Desktop.
Save saisurya-kat/3e4fe2d1cf1052c4ad209f738d265ad9 to your computer and use it in GitHub Desktop.

List of useful Docker commands:

Identifying an existing docker image

docker search <image_name>
Eg: docker search redis

Running a docker image

docker run <image_name>

To run in detached mode

docker run -d <image_name>
Eg: docker run -d redis

To run in interactive mode

docker run redis -it

Running a specific version of an image

docker run redis:3.2
to use the latest image version
docker run redis:latest

Running the image on container with a given port and an alias name

docker run -d --name <alias_name> -p 6379:6379 redis:latest
Eg: docker run -d redis reditDefPort -p 6379:6379 redis latest

To assign a dynamic port for the container we can use the dynamic version

docker run -d --name redisDynamic -p 6379 redis:latest

List the running containers

docker ps

To see more details of the running container such as ip,port etc

docker inspect <friendly-name|container-id>
Eg: docker inspect redis

To see the logs written by the container to console

docker logs <friendly-name|container-id>
Eg: docker logs redis

To save the data on the docker host(as volumes) rather than the container(For persistent data storage)

docker run -d --name redisMapped -v /opt/docker/data/redis:/data redis (or)
docker run -d --name redisMapped -v $PWD/data:/data redis

List all the docker images on the host

docker images
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment