Run Dokcer on WSL2 (Windows Subsystem for Linux).
--Windows10 Pro 64bit 1909 (OS build 18363,1198)
Please install WSL2 referring to the following.
-Introduction of WSL2 --Linux on Windows (Windows Subsystem for Linux 2)
--Download DockerDesktop for Windows.
If you use it in an environment that requires a proxy, set up a proxy as needed.
-[Start] —-> [Docker Desktop] --Setting button at the top of the screen [⚙] —-> [Resources] --Turn on [Manual proxy configuration] --Enter the proxy server information.
C:\> docker run -d -p 80:80 --name docker_getting_started docker/getting-started
↑ The container name is specified by --name for easy management. If not specified, the name will be set automatically.
Unable to find image 'docker/getting-started:latest' locally
latest: Pulling from docker/getting-started
188c0c94c7c5: Pull complete
617561f33ec6: Pull complete
7d856acdaa9c: Pull complete
a0d3c6e28e6d: Pull complete
af69a9b963c8: Pull complete
0739f3815ad8: Pull complete
7c7b75d0baf8: Pull complete
Digest: sha256:b821569034e3b5fae03b40e64a866017067f3bf17effe185b782bdbf02179528
Status: Downloaded newer image for docker/getting-started:latest
968e5ed0c3110cfc0d3a1db69d9a4d3cba232fcb28ebe3f9ae76b1ca80699b14
http://localhost:80/
C:\> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker/getting-started latest 021a1b85e641 3 days ago 27.6MB
C:\> docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
968e5ed0c311 docker/getting-started "/docker-entrypoint.…" About a minute ago Up About a minute 0.0.0.0:80->80/tcp docker_getting_started
C:\> wsl -l -v
NAME STATE VERSION
* Ubuntu-20.04 Running 2
docker-desktop-data Running 2
docker-desktop Running 2
A distribution for Docker has been introduced.
I'll go inside.
C:\> wsl -d Ubuntu-20.04
Let's operate it in Linux.
$ uname -r
4.19.128-microsoft-standard
$ cat /etc/issue
Ubuntu 20.04.1 LTS \n \l
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
968e5ed0c311 docker/getting-started "/docker-entrypoint.…" 3 minutes ago Up 3 minutes 0.0.0.0:80->80/tcp docker_getting_started
The result of the docker command on Ubuntu is the same as the result of the docker command on Windows. You can see that there is a reality on Ubuntu.
Have you been able to introduce it?
Let's use a Python container. I will try the following two.
C:\> docker pull python
Using default tag: latest
latest: Pulling from library/python
6c33745f49b4: Pull complete
c87cd3c61e27: Pull complete
05a3c799ec37: Pull complete
a61c38f966ac: Pull complete
c2dd6d195b68: Pull complete
29b9446ae7bd: Pull complete
09cf96c794f9: Pull complete
f674fd97fba7: Pull complete
ffc24df6b7b8: Pull complete
Digest: sha256:b273b08cf9fe6b07ee4c2466095e5a4ac5301ade62106b7e7817eba00a684613
Status: Downloaded newer image for python:latest
docker.io/library/python:latest
C:\> docker images
C:\> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
python latest 0611cf846c85 16 hours ago 885MB
docker/getting-started latest 021a1b85e641 3 days ago 27.6MB
I was able to confirm that the python image was downloaded.
Prepare a simple program that outputs hello. C:\work\docker\playgraound\python\hello.py
print('hello')
ans = 5**2
print(f'5 squared{ans}')
C:\> docker run -itd -v C:\work\docker\playground\python:/mnt/python --name playground_python python
80de49d79dfba3d65cb944f7d8348ab2d9f090a8438d67afb81e2e91413a5f16
↑ The docker id is displayed.
C:\> docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
80de49d79dfb python "python3" 19 seconds ago Up 16 seconds playground_python
968e5ed0c311 docker/getting-started "/docker-entrypoint.…" 3 hours ago Up 3 hours 0.0.0.0:80->80/tcp docker_getting_started
A new container environment was created based on the downloaded python image.
C:\> docker exec -it playground_python /bin/bash
# python --version
Python 3.9.1
# ls /mnt/python
hello.py
# python /mnt/python/hello.py
hello
5 squared is 25
You can operate files on Windows.
# python -c "ans=10*10; print(ans)"
100
# exit
C:\> docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
80de49d79dfb python "python3" 12 minutes ago Up 12 minutes playground_python
968e5ed0c311 docker/getting-started "/docker-entrypoint.…" 3 hours ago Up 3 hours 0.0.0.0:80->80/tcp docker_getting_started
I found that file sharing can be easily done with docker and windows. I think development productivity will increase. However, please note that a warning is written when the performance drops.
--Docker document Japanese localization project
--Latest Linux container technology that supports Docker --A good book that explains how Docker works through Linux functions --Nikkei BP (2015/3/25) --Kindle version for only 990 yen
Recommended Posts