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!"!
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]
...
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
docker.io/library/ubuntu:18.04
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
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
root@c75e4e2811e0:/#
When installing packages on Linux, first update and then install the required packages.
root@c75e4e2811e0:/# 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.
root@c75e4e2811e0:/# apt-get install vim
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
...
To exit the Docker container and return to the host OS, use the ʻexit` command.
root@c75e4e2811e0:/# exit
exit
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
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
ubuntu_test1
$ docker attach ubuntu_test1
root@c75e4e2811e0:/#
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