Create container
docker create <container_image>
Remove image
docker rmi <container_image>
Start container (start container without output)
docker start <container_id>
Start container (start container with output)
docker start -a <container_id>
Run container (install, create and start container)
docker run <container_image> <command_when_start>
# -p is port mapping <local_browsing_port>:<container_running_port>
docker run -p 8000:8080 <container_image>
# -d is to executed in background
docker run -d <container_image>
# -p <host>:<container>
# -v <not_included> -v <host_path>:<container_path>
docker run -it -p 8080:80 -v /app/node_modules -v $(pwd):/app <container_id>
List running container
docker ps
List all container
docker ps -a
Removing stopped container
docker system prune
Get log for certain container
docker logs <container_id>
Stop container (it will wait maybe 10 sec before it kill it)
docker stop <container_id>
Kill container (kill container immediately)
docker kill <container_id>
Execute an additional command in container
# -i allow to enter in text (input) to containers terminal
# -t show a nice formatted input (eg: root@ip_address ~% )
# -it is combined flag between -i and -t
docker exec -it <container_id> <command_to_execute>
Getting full access or command prompt terminal in container
# name_of_programs (eg: bash, powershell, zsh, sh)
docker exec -it <container_id> <name_of_program>
Run docker file / Create docker image
# go to Dockerfile/project directory
docker build <Dockerfile directory>
# create docker image with name
docker build -t <my_docker_id>/<project>:<version> <Dockerfile directory>
# -f is for custom filename other than Dockerfile
docker build -f <filename> <Dockerfile directory>
Create docker image from container
# -c is to set default command (in array) when image is running
docker commit -c "CMD ['ls', '-lah', '/var/www/html']" <container_id>
Run docker compose
docker-compose up
# —build is to build/rebuild containers
docker-compose up —build
# -d is to executed in background
docker-compose up -d
Stop docker compose
docker-compose down
List container in project with docker-compose
docker-compose ps
Top comments (0)