I installed Docker on Ubuntu 18.04 on WSL2 and tried to touch it, so I will leave a note.
Ubuntu construction on WSL2 is summarized in the following article. I tried to build Ubuntu 18.04 on WSL
19.03.13
Install by referring to the following site. Install Docker on Ubuntu 18.04 LTS
Update the packages, install the required packages, and install the official Docker GPG public key.
$ sudo apt update
$ sudo apt install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo apt-key fingerprint 0EBFCD88
$ sudo add-apt-repository \
    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
    $(lsb_release -cs) \
    stable"
Install the latest version of Docker.
$ sudo apt update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
Confirm the installation.
$ sudo docker --version
$ sudo systemctl status docker
Create a proxy setting file and write the required settings.
$ sudo mkdir -p /etc/systemd/system/docker.service.d
$ sudo vi /etc/systemd/system/docker.service.d/http-proxy.conf
http-proxy.conf
[Service]
  Environment="HTTP_PROXY=http://proxy.example.com:8080/"
  Environment="HTTPS_PROXY=http://proxy.example.com:8080/"
Apply the changes and reflect the settings. Make sure that it is set at the end.
$ sudo systemctl daemon-reload
$ sudo systemctl restart docker
$ systemctl show --property=Environment docker
When the information described in the configuration file is displayed, the process is complete.
First, let's check the current situation.
$ docker images
An error will occur with Permission Denied.
Put the target user in the Docker group. Please log in to the target user once.
$ sudo usermod -aG docker ${USER}
$ su - ${USER}
Confirm that the settings have been made.
$ docker images
If no errors occur, you're done.
$ sudo systemctl start docker
$ sudo systemctl stop docker
$ sudo systemctl status docker
$ docker search [OPTIONS] TERM
By putting httpd, mysql, etc. in TERM, the provided repository is displayed.
For example, try searching with httpd.
$ docker search httpd
The following results were returned.
NAME                                    DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
httpd                                   The Apache HTTP Server Project                  3261                [OK]
centos/httpd-24-centos7                 Platform for running Apache httpd 2.4 or bui…   36
centos/httpd                                                                            33                                      [OK]
arm32v7/httpd                           The Apache HTTP Server Project                  9
polinux/httpd-php                       Apache with PHP in Docker (Supervisor, CentO…   4                                       [OK]
salim1983hoop/httpd24                   Dockerfile running apache config                2                                       [OK]
solsson/httpd-openidc                   mod_auth_openidc on official httpd image, ve…   1                                       [OK]
publici/httpd                           httpd:latest                                    1                                       [OK]
clearlinux/httpd                        httpd HyperText Transfer Protocol (HTTP) ser…   1
hypoport/httpd-cgi                      httpd-cgi                                       1                                       [OK]
jonathanheilmann/httpd-alpine-rewrite   httpd:alpine with enabled mod_rewrite           1                                       [OK]
dariko/httpd-rproxy-ldap                Apache httpd reverse proxy with LDAP authent…   1                                       [OK]
lead4good/httpd-fpm                     httpd server which connects via fcgi proxy h…   1                                       [OK]
dockerpinata/httpd                                                                      0
interlutions/httpd                      httpd docker image with debian-based config …   0                                       [OK]
appertly/httpd                          Customized Apache HTTPD that uses a PHP-FPM …   0                                       [OK]
amd64/httpd                             The Apache HTTP Server Project                  0
manasip/httpd                                                                           0
trollin/httpd                                                                           0
e2eteam/httpd                                                                           0
manageiq/httpd_configmap_generator      Httpd Configmap Generator                       0                                       [OK]
itsziget/httpd24                        Extended HTTPD Docker image based on the off…   0                                       [OK]
manageiq/httpd                          Container with httpd, built on CentOS for Ma…   0                                       [OK]
ppc64le/httpd                           The Apache HTTP Server Project                  0
You can see that The Apache HTTP Server Project officially publishes an image named httpd.
$ docker pull [OPTIONS] NAME[:TAG|@DIGEST]
Let's get the httpd image we searched for earlier.
$ docker pull httpd
If you do not specify TAG, the latest version will be pulled.
Using default tag: latest
latest: Pulling from library/httpd
852e50cd189d: Pull complete
67d51c33d390: Pull complete
b0ad2a3b9567: Pull complete
136f1f71f30c: Pull complete
01f8ace29294: Pull complete
Digest: sha256:fddc534b7f6bb6197855be559244adb11907d569aae1283db8e6ce8bb8f6f456
Status: Downloaded newer image for httpd:latest
docker.io/library/httpd:latest
$ docker images [OPTIONS] [REPOSITORY]
Let's take a look at the image that was pulled earlier.
$ docker images
It will be displayed as follows.
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
httpd               latest              0a30f4c29d25        4 days ago          138MB
$ docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Let's start httpd earlier.
$ docker run -d -p 8080:80 httpd
The alphanumeric characters displayed below when you execute the docker run command will be the container ID, and when you specify this container in the future, specify this ID. I will explain the options. -d: Run in the background (otherwise the prompt will be stolen by the container. Log out and you'll be back on the host side) -p: Specify port (this time the local port is 8080 and the container port is 80)
Another boot method. When started with this, the prompt becomes the prompt in the container.
$ docker run -p 8080:80 --name test01 -it httpd /bin/bash
--name: Specify container name -it: Specify image name / bin / bash: Specify login command
$ docker ps [OPTIONS]
To see including stopped processes, add the -a option. Basically, you should type the following command.
$ docker ps -a
The execution result is displayed as follows.
CONTAINER ID        IMAGE               COMMAND              CREATED             STATUS                      PORTS                  NAMES
cf4beeb4be04        httpd               "httpd-foreground"   3 seconds ago       Up 2 seconds                0.0.0.0:8080->80/tcp   pedantic_cohen
168d4374aa73        httpd               "/bin/bash"          7 minutes ago       Exited (0) 4 minutes ago                           test01
The view is as follows.
| Column name | Explanation | 
|---|---|
| CONTAINER ID | First 12 digits of container ID | 
| IMAGE | Original image name of the container | 
| COMMAND | Command given at startup(What was specified at the end at startup) | 
| CREATED | Elapsed time from the container creation date | 
| STATUS | Start / stop status | 
| PORTS | Binding port(Host side 8080:Container side 80) | 
| NAMES | The name of the container(At startup--What is specified by name) | 
$ docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
Try logging in to the cf4beeb4be04 container above.
$ docker exec -it cf4beeb4be04 /bin/bash
$ docker stop [OPTIONS] CONTAINER [CONTAINER...]
Let's stop the container that was started earlier.
$ docker stop 5b43901894115d72415d265488225b957050accffcb27ce16382c97479be1d75
$ docker start [OPTIONS] CONTAINER [CONTAINER...]
Let's start the container that was stopped earlier.
$ docker start 5b43901894115d72415d265488225b957050accffcb27ce16382c97479be1d75
$ docker rm [OPTIONS] CONTAINER [CONTAINER...]
test01 Try deleting the container.
$ docker rm test01
Try running the docker ps command again.
CONTAINER ID        IMAGE               COMMAND              CREATED             STATUS                      PORTS               NAMES
cf4beeb4be04        httpd               "httpd-foreground"   17 minutes ago      Exited (0) 4 minutes ago                        pedantic_cohen
You can see that it has been deleted.
docker rmi [OPTIONS] IMAGE [IMAGE...]
Let's delete the httpd image. Specify the container ID displayed by docker images.
docker rmi 0a30f4c29d25
If it is deleted by docker images again, it is complete.
This time, I installed Docker on Ubuntu 18.04 and tried to summarize the basic "key" level commands of Docker. In the future, I would like to summarize what I noticed while building.
Recommended Posts