Introduction of Docker Hub and commands Self-learning ①

While learning Docker, many commands came out, so I will output them.

What is Docker Hub?

image.png The name of the registry where Docker image is managed (like Git Hub). There are other registries that manage Docker images, one of which is the Docker Hub.

Repository sharing

Like Git Hub, Docker Hub can be managed in the repository. You can easily set up a development environment by sharing the repository (image) with various people such as teams. An image of cloning a remote repository locally in GitHub.

To use Docker Hub

Make a new registration from Website of Docker Hub. Open a terminal and log in.

$ docker login 
Login Succeeded

Is displayed, login is successful.

Pull the repository (image) to local (Host)

Pull the repository managed by Docker Hub locally.

$ docker pull <image name>

For example, if testOS is the repository name

$ docker pull WindowsOS

This completes the repository clone locally.

Create a container

Run the run command to work in the container that contains the Windows OS.

$ docker run -it testOS bash

Now you can create a container and go inside it. Here, we will organize the information in the next part.

Why create a container?

I just pulled a repository (image) called testOS locally from Docker Hub. However, at this point you cannot use testOS in your local environment.

For example, testOS is required in the development environment of the application to be created, so we want to be able to use testOS. Therefore, you can use testOS by creating a container that contains testOS and working in that container.

To get out of the container

$ exit

You can exit the container with this command.

How to check locally managed containers

$ docker ps -a

If you don't add -a, only moving containers will be displayed, so you need -a to display all.

How to check locally managed images

$ docker images

How to re-enter the container after exiting

If you exit the container with the exit command after run, the container will be in the exited state. As it is, the container has not started and you cannot enter it, so start it again.

$ docker restart

Then, with the exec command, type the command to enter the container again.

$ docker exec -it <name of container> bash 

How to save changes to Docker image

Suppose you need Ruby, PHP, or Javascript in your development environment. One person has set up to handle Ruby, PHP, Javascript in the container.

It takes time and effort for other people to build the same environment. → Save the working environment of the container set by one person in the image (repository) and provide it to solve the problem!

$ docker commit <container> <image>

This command saves the changes in the container to image.

Match names by tag before pushing image to Docoker Hub

Create a new repository with Docker Hub in advance. (Here, new-repo) The names must match, so tag them.

$ docker tag old-repo:updated username/new-repo

updated in the local repository where old-repo made changes, with tags representing updates. Match the name with username / new-repo to the newly created "new-repo" in Docker Hub.

Push image to Docker Hub

$ docker push username/new-repo

This completes the push to the repository managed by Docker Hub By pulling, you can handle the modified image (repository) locally.

How to delete image

$ docker rmi <image>

Recommended Posts

Introduction of Docker Hub and commands Self-learning ①
Introduction of Docker --Part 1--
Overview of Docker and containers
[Docker] Introduction of basic Docker Instruction
Summary of frequently used Docker commands
Introduction to Docker (1) Frequently used commands
Frequently used functions and commands of Xcode
[Challenge Docker from 0] Overview and terms of Docker
Introduction and precautions of gem Friendly Id
Introduction and usage explanation of Font Awesome
[Docker] Introduction to docker compose Basic summary of docker-compose.yml
Introduction of pay.jp
Simple installation of nginx and Docker using ansible
Introduction and basic usage of Simple Calendar gem
Introduction of milkode
Docker basic commands
Introduction of Rspec and Japanese localization of error messages
A reminder of Docker and development environment construction
Introduction and introduction of management screen generation gem Administrate
Verification of the relationship between Docker images and containers
The story of pushing a Docker container to GitHub Package Registry and Docker Hub with GitHub Actions
Docker installation and initialization
[Rails] Introduction of PAY.JP
Docker Frequently used commands
SystemSpec introduction and writing
Introduction of user authentication
Japanese localization of Docker container of CentOS7 / CentOS8 and Japan time setting
Getting Started with GitHub Container Registry instead of Docker Hub
Introduction purpose of ActiveHash and simple flow to application implementation
[Introduction] Installation of Docker Desktop for Mac for the first time and setup of virtual environment construction of CentOS