Docker basic commands

Use Docker instead of the Python virtual environment to analyze data in Python and develop web applications. I summarized the Docker basic commands.

Pull and push from Docker Hub

Pull the image from Docker Hub, run the container, create the image from the container and push it to Docker Hub.

command Explanation
docker login Log in to docker
docker pull <image> Get image from docker hub
docker run -it <image> bash Run the container from the image with a bash program. run is create+start. bash is<command>Is entered, overwriting the default command.
exit Get out of the container
docker ps -a Show list of containers process status.-Also displays containers stopped at a
docker images Display image list
docker restart <container> Reboot container status from exit to up
docker exec -it <container> bash Run the container in a bash program
docker commit <container> <image> Create an image from a container
docker tag <source> <target> Give the image a tag name (make it the same name as the docker hub repository to upload to docker hub)
docker push <image> Push to Docker Hub
docker rmi <image> Delete image

Delete command

command Explanation
docker rm <container> Delete container
docker system prune Bulk delete containers
docker rmi <image> Delete image
docker image prune Delete images in bulk

run option

Options when starting the container.

option Explanation
-it Basically use.-i can be input.-t makes the display beautiful
--name <container_name> <image> Specify the container name
--d <image> Detach after starting the container (run in the background)
--rm <image> Delete the container after exiting (one-time container)
-v <host/path>:<container/path> File system sharing
-u $(id -u):$(id -g) Access to files
-p <host_port>:<container/port> Connect ports
--cpus <#ofCPUs> --memory <byte> Computer resource limit. Of the following command<something>Check the current situation by putting cpu etc. in

You can find out more about the container with docker inspect <container> | grep -i <something>.

Create Image from Dockerfile

command Explanation
docker build <directory> <directory>To ".Is often specified. Move to the folder where Dockerfile is saved and build in the current directory
docker build -t <name> <directory> Specify the image name
docker build -f <docker file> <build context> Used when the Dockerfile is not in the building context (current directory, etc.). If you have multiple Dockerfiles for development and test

Keywords related to docker build: Docker daemon, build context

Recommended Posts

Docker basic commands
Docker basic summary
docker basic command
Docker terms and commands
Docker Frequently used commands
Docker Compose basics and commands
[Docker] Introduction of basic Docker Instruction
[Ruby] List of basic commands
Docker Compact Manual (1: Basic / Basic Command)
docker
Summary of frequently used Docker commands
Docker related commands (notes for yourself)
Introduction to Docker (1) Frequently used commands
docker memo
kubernetes + docker
spring × docker
About Docker
Docker Intellij
Basic type-java
Basic knowledge
Docker basics
Edit Mysql with commands in Docker environment
Docker installation
Basic Rails commands you want to learn
About Docker
Docker command
Introduction of Docker Hub and commands Self-learning ①
Docker memorandum
Understand Docker
Docker memorandum
Commands that helped resolve errors in Docker
[Docker] Introduction to docker compose Basic summary of docker-compose.yml
(Basic authentication) environment variables in rails and Docker