Try putting Docker in ubuntu on WSL

I installed Docker on Ubuntu 18.04 on WSL2 and tried to touch it, so I will leave a note.

Work environment

Ubuntu setup

Ubuntu construction on WSL2 is summarized in the following article. I tried to build Ubuntu 18.04 on WSL

Docker version



  1. Docker installation
  2. Various Docker commands

1. Docker installation

Install by referring to the following site. Install Docker on Ubuntu 18.04 LTS

Set up a Docker repository

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 \
$ curl -fsSL | sudo apt-key add -
$ sudo apt-key fingerprint 0EBFCD88
$ sudo add-apt-repository \
    "deb [arch=amd64] \
    $(lsb_release -cs) \

Docker installation

Install the latest version of Docker.

$ sudo apt update
$ sudo apt-get install docker-ce docker-ce-cli

Confirm the installation.

$ sudo docker --version
$ sudo systemctl status docker

Perform the following when setting the Proxy.

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



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.

Make settings to execute Docker commands without sudo.

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.

2. Various Docker commands

Docker start / stop / status check

$ sudo systemctl start docker
$ sudo systemctl stop docker
$ sudo systemctl status docker

Image search

$ 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.

Image acquisition

$ 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

Image list display

$ 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

Start container

$ 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

Checking the container process

$ 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      >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)

Login to the running container


Try logging in to the cf4beeb4be04 container above.

$ docker exec -it cf4beeb4be04 /bin/bash

Stop container


Let's stop the container that was started earlier.

$ docker stop 5b43901894115d72415d265488225b957050accffcb27ce16382c97479be1d75

Starting a stopped container


Let's start the container that was stopped earlier.

$ docker start 5b43901894115d72415d265488225b957050accffcb27ce16382c97479be1d75

Delete 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.

Delete image

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

Try putting Docker in ubuntu on WSL
Use docker in proxy environment on ubuntu 20.04.1
Microservices 101-I tried putting Docker on Ubuntu-
Try DisplayLink on Ubuntu 20.04
Docker installation on WSL2
Try running ScalarDB on WSL Ubuntu (Environment Construction)
Docker on Ubuntu18.04 on WSL2 and VSCode installation instructions
Try running ScalarDB on WSL Ubuntu (Sample application creation)
Install Docker on Ubuntu Server 20.04
Try Docker on Windows 10 Home
Oracle Java 8 on Docker Ubuntu
Install Java on WSL Ubuntu 18.04
Ruby installation on WSL2 + Ubuntu 20.04
Install docker and docker-compose on ubuntu in the shortest process
Configuration script for using docker in proxy environment on ubuntu 20.04.1
Try using Redmine on Mac docker
Try putting CentOS 8 on Raspberry Pi 3
Elmer / Ice installation (Ubuntu on WSL)
Using Docker on Windows10 Home WSL2
Easily try C # 9 (.NET 5) on Docker
Until you put Ubuntu 20 on Windows 10 Home and WSL2 and run Docker
Ubuntu on WSL2: Cannot connect to the Docker daemon at unix
Windows Docker: Disk pressure on WSL files
WSL2 + Ubuntu 20.04 Install Vivado in LTS environment
Run NordVPN on Docker (Windows) Ubuntu container
Introducing Docker Desktop for Windows on WSL2
Use cljstyle with Spacemacs on Ubuntu on WSL2
Try the Docker environment on AWS ECS
Until you run apache on ubuntu on docker
Run Ubuntu + ROS with Docker on Mac
Put Zabbix in Ubuntu with Docker and monitor Docker on the same host
Try running MPLS-VPN with FR Routing on Docker
Docker on wsl2 no longer says yes or no
Liberty on Docker
Just install Laravel8 on docker in PHP8 environment
Try running OSPF with FR Routing on Docker
Docker in LXD
Operate Docker Desktop for Windows on Linux (WSL)
tmux on Ubuntu
Redmine on Docker
Install Ubuntu 20.04 in virtual box on windows10 and build a development environment using docker
Systemctl cannot be used on Ubuntu inside Docker container
I built an Ubuntu environment on Windows 10 using WSL2.
Command memo to install xeyes in ubuntu docker environment
Feel free to try Elasticsearch cluster with WSL2 + Docker
Install Rust in WSL2 Ubuntu environment and build WASM build environment
Screen recording on Ubuntu 20.04
Web Bluetooth on Ubuntu20.04
Reinstall Kubernetes on Ubuntu 19.10
Docker installation on CentOS 6
Use Flutter on Ubuntu
Try OpenLiteSpeed on CentOS8
python notes on docker
Explode Docker with WSL2
Try LetCode in Ruby-TwoSum
Install Docker on Manjaro
Install Ruby on Ubuntu 20.04
Setting JAVA_HOME on Ubuntu
Put JetBrains on Ubuntu
Use mkdir on ubuntu
Try actions on GitHub [actions]