Common used docker commands:
List of running containers
$ docker ps
$ docker ps -a // show all containers running & stopped
List of docker images
$ docker images
$ docker image ls
Starts a new container to run image. $ docker run = docker pull + docker start
$ docker run {image-name}
$ docker run -d {image-name} // with detach mode
// port binding with host and container
$ docker run -p6000:6379 // binding host port 6000 to docker container 6379
$docker run -d -p6000:6379 --name {my-custom-name} {image-name}
Stop/start a container by container ID
$ docker stop {container-id}
$ docker start {container-id}
View logs
$ docker logs {container-id}
$ docker logs {container-name}
Using interactive terminal on this container/image
$ docker exec -it {container-id} /bin/bash
Docker network
$ docker network ls
Docker Network create
$ docker network create {mongo-network}
Example of Network creation for mongo-network. docker run with environment variables
// start mongodb. create mongo netowkr with mongodb
$ docker run -d -p 27017:27017
-e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=password
--net mongo-network
--name mongodb
mongo// start mongo-express. run express to connect to mongoDB
$ docker run -d
-p 8081:8081
-e ME_CONFIG_MONGODB_ADMINUSERNAME=admin
-e ME_CONFIG_MONGODB_ADMINPASSWORD=password
-e ME_CONFIG_MONGODB_SERVER=mongodb
--net mongo-network
--name mongo-express
mongo-express
################# More docker command options
More "docker image ... " commands:
$ docker image build //Build an image from a Dockerfile$ docker image history //Show the history of an image$ docker image import //Import the contents from a tarball to create a file system image$ docker image inspect //Display detailed information on one or more images$ docker image load //Load an image from a tar archive or STDIN$ docker image ls //List images$ docker image prune //Remove unused images$ docker image pull //Pull an image or a repository from a registry$ docker image push //Push an image or a repository to a registry$ docker image rm //Remove one or more images$ docker image save //Save one or more images to a tar archive (streamed to STDOUT by default)$ docker image tag //Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE