[LINUX] [Super basic] Docker command procedure manual when using Ubuntu on Mac


I've been trying dual boot and VirtualBox, thinking "I usually use a Mac, but I also want to use Ubuntu depending on the purpose and purpose ...", but first I use Ubuntu easily on a Mac. If so, I came to the conclusion that it is better to use Docker! I've heard the name Docker before, but I think there are actually many engineers who haven't used Docker properly ...! I've used Docker for work in the past, but it's been a few years since I joined the company, so I didn't know much about Docker ... So, taking this opportunity, I would like to make a [super basic] Docker command procedure manual so that I can say "I have mastered the basics of Docker!"!

1. Search for Docker images

First of all, search for the OS image on Docker Hub. Docker Hub is a service that allows you to publish and share user-created Docker containers.

$ docker search ubuntu
NAME                                                      DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
ubuntu                                                    Ubuntu is a Debian-based Linux operating sys…   10214               [OK]                
dorowu/ubuntu-desktop-lxde-vnc                            Docker image to provide HTML5 VNC interface …   366                                     [OK]
rastasheep/ubuntu-sshd                                    Dockerized SSH service, built on top of offi…   236                                     [OK]
consol/ubuntu-xfce-vnc                                    Ubuntu container with "headless" VNC session…   197                                     [OK]

2. Download Docker image

You can freely download the Docker container published on Docker Hub and save the Docker image on your own server.

$ docker pull ubuntu:18.04
18.04: Pulling from library/ubuntu
7ddbc47eeb70: Pull complete 
c1bbdc448b72: Pull complete 
8c3b70e39044: Pull complete 
45d437916d57: Pull complete 
Digest: sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d
Status: Downloaded newer image for ubuntu:18.04

3. Check saved Docker images

Check the Docker image stored on your server.

$ docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              18.04               775349758637        4 weeks ago         64.2MB

4. Deploy Docker container

Launch a Docker container using the saved Docker image. There are various options when deploying a Docker container. If you want to find out more about the options, please refer to the URL below. https://docs.docker.com/v17.12/edge/engine/reference/commandline/run/ The three options I use most often are --name, -v, and -it. You can specify the container name with --name. -v allows you to mount the host OS directory on the guest OS. In other words, you can access the existing folders you are using on your Mac from the Docker container. Finally, -it allows you to assign a pseudo terminal to your Docker container. This is required as you can use Bash on the Docker container.

$ docker run --name ubuntu_test1 -v ~/ws:/home/ -it ubuntu:18.04
[email protected]:/# 

5. Package installation

When installing packages on Linux, first update and then install the required packages.

[email protected]:/# apt-get update
Get:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Get:2 http://archive.ubuntu.com/ubuntu bionic InRelease [242 kB]
Get:17 http://archive.ubuntu.com/ubuntu bionic-backports/main amd64 Packages [2496 B]
Get:18 http://archive.ubuntu.com/ubuntu bionic-backports/universe amd64 Packages [4235 B]
Fetched 17.3 MB in 6s (2837 kB/s)                                                                                                                                                                                  
Reading package lists... Done

I use Vim as a text editor, so I'll have Vim available with the following command. Follow the same procedure to install the package.

[email protected]:/# apt-get install vim
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:

6. Exit Docker container

To exit the Docker container and return to the host OS, use the ʻexit` command.

[email protected]:/# exit

7. Check the status of Docker container

To check the status of the Docker container, use the following command. From STATUS, you can also see that the Docker container is closed.

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS                      PORTS               NAMES
c75e4e2811e0        ubuntu:18.04        "/bin/bash"         About a minute ago   Exited (0) 13 seconds ago                       ubuntu_test1

8. Resume Docker container

To restart a closed Docker container, use the docker start, docker attach commands. Specify the container name used during deployment. If you follow the above procedure, you can continue development using the Docker container with the environment built.

$ docker start ubuntu_test1
$ docker attach ubuntu_test1
[email protected]:/# 

in conclusion

I created a [super basic] Docker command procedure manual. I know Docker exists, but I've never actually used it! I don't really understand how to use it! I think it will be a useful article for engineers like me! Next, I will summarize how to create and operate a Dockerfile!

Recommended Posts

[Super basic] Docker command procedure manual when using Ubuntu on Mac
Error, warning when using TensorFlow on Mac
CPU usage is 100% when using pygame on Ubuntu 16.04
Error around GUI when using PyQt5 on Ubuntu (WSL2)
Troublesome story when using Python3 with VScode on ubuntu
Minimum memo when using Python on Mac (pyenv edition)
Minimum notes when using Python on Mac (Homebrew edition)
Python environment construction procedure memo using Docker on Windows10 Home
Docker command super abbreviated version
Create command shortcuts on Ubuntu 16.04
Install Docker on WSL Ubuntu 18.04
Introducing Python using pyenv on Ubuntu 20.04
Preparing python using vscode on ubuntu
Completion of docker command on Linux
Using a serial console on Ubuntu 20.04
Linux command 16 procedure manual folder (completed)
Run Yocto on Ubuntu using QEMU.
(Beginner) Notes on using pyenv on Mac