Docker autostart settings with wsl2

I tried using wsl2, and it seems that Docker cannot be set to start automatically. It is troublesome to type the service command every time, so I considered it

Set to sudo so that users can start without a password

$ sudo visudo
# docker deamon auto up
User ALL=(ALL:ALL) NOPASSWD: /usr/sbin/service docker start
When stopped
$ service docker status
 * Docker is not running
At startup
$ service docker status
 * Docker is running

Added to start .bashrc only when docker is not running

$vim .bashrc
echo $(service docker status | awk '{print $4}') #Show startup status
if test $(service docker status | awk '{print $4}') = 'not'; then #State of standstill
        sudo /usr/sbin/service docker start #Start-up

With this setting, when entering wsl2, Docker will start if it is stopped. image.png

Recommended Posts

Docker autostart settings with wsl2
Explode Docker with WSL2
Php settings with Docker
Build docker environment with WSL
Image flew when updating Docker with WSL2
GPU recognition with docker using WSL2 (August 2020)
Install Docker with WSL2 Memo ([Part 2] Docker introduction)
Comfortable development life with WSL2 + Docker Desktop + GPU
Launch MariaDB with Docker
Rails deploy with Docker
Run Pico with docker
Use Puphpeteer with Docker
Operate Emby with Docker
Try WildFly with Docker
Use ngrok with Docker
Run Payara with Docker
[Docker] Connection with MySQL
Getting Started with Docker
Disposable PHP with Docker
Docker installation on WSL2
Install Composer with Docker
Feel free to try Elasticsearch cluster with WSL2 + Docker
Build Java development environment with WSL2 Docker VS Code
Comfortable Docker environment created with WSL2 CentOS7 and Docker Desktop
Create Chisel development environment with Windows10 + WSL2 + VScode + Docker
Pytorch execution environment with Docker
Use GDAL with Python with Docker
Deploy with EC2 / Docker / Laravel
Run TAO Core with Docker
Docker management with VS Code
Set up GitLab with docker
Run Rails whenever with docker
Get started with DynamoDB with docker
[Docker] Rails 5.2 environment construction with docker
Spring Boot starting with Docker
Version control CocoaPods with Docker
Web application built with docker (1)
I tried BIND with Docker
React environment construction with Docker
Build DynamoDB local with Docker
[Docker] Use whenever with Docker + Rails
Measures for permissions when building MySQL with Docker on WSL2
Using PlantUml with Honkit [Docker]
Build Go development environment with WSL2 + Docker Desktop + VSCode (Remote --Containers)
Rails + MySQL environment construction with Docker
Create a Vue3 environment with Docker!
Node.js environment construction with Docker Compose
Run lambda with custom docker image
Deploy a Docker application with Greengrass
Build Couchbase local environment with Docker
Install java with Ubuntu 16.04 based Docker
Build a Node.js environment with Docker
Environment construction with Docker for beginners
[PDO → DB connection with docker, PHP]
Why use orchestration tools with Docker
Build PlantUML environment with VSCode + Docker
Try running cloudera manager with docker
Molecular phylogenetics exercise with docker (working)
IP address interfered with Docker bridge
Build environment with vue.js + rails + docker
Read dump file with Docker MySQL