Docker Basic Notes
This post is just a simple note. More detail in this video: https://www.youtube.com/watch?v=3c-iBn73dDE Difference Image and Container CONTAINER is a running environment for IMAGE virtual file system port blinded: talk to application running inside of container application image: postgres, redis, mongo, … redis in dockerhub are images docker pull postgres docker pull redis # lists installed images docker images docker run redis # `-d` means running in detached mode docker run -d redis # lists running container docker ps # lists running and stopped container docker ps -a # stops the container docker stop <CONTAINER ID> # start the container docker start <CONTAINER ID> # pulls image and starts container docker run redis:4.0 CONTAINER Ports vs HOST ports Multiple containers can run on your host machine Your laptop has only certain ports available Conflict when same port on host machine host docker Port 5000 Port 5000 Port 3000 Port 3000 Port 3001 Port 3000 docker run -p6000:6379 redis docker logs <CONTAINER ID> docker logs <CONTAINER NAMES> docker run -d -p6000:6379 --name redis-older redis:4.0 # it Interactive Terminal docker exec -it <CONTAINER ID> /bin/bash docker exec -it <CONTAINER NAMES> /bin/bash # if no bash installed docker exec -it <CONTAINER ID> /bin/sh docker exec -it <CONTAINER NAMES> /bin/sh # create a new container from a image docker run # start a exist container docker start docker pull mongo docker pull mongo-express docker network ls docker network create <NETWORK NAME> docker run -d \ -p 27017:27017 \ -e MONGO_INITDB_ROOT_USERNAME=admin \ -e MONGO_INITDB_ROOT_PASSWORD=password \ --network mongo-network \ --name mongodb \ mongo docker run -d \ -p 8081:8081 \ -e ME_CONFIG_MONGODB_ADMINUSERNAME=admin \ -e ME_CONFIG_MONGODB_ADMINPASSWORD=password \ -e ME_CONFIG_MONGODB_PORT=27017 \ -e ME_CONFIG_MONGODB_SERVER=mongodb \ --net mongo-network \ --name mongo-express \ mongo-express docker logs <CONTAINER ID> -f docker logs <CONTAINER ID> | tail docker logs <CONTAINER ID> | more Docker Compose docker run command ...