There was a time when I thought it didn't matter if I used Docker on Windows or Linux. Aside from the difference in behavior depending on the OS, it seems that there are differences depending on the containerization method. There are two main approaches to creating a container on Windows. One is to use Hyper-V and the other is to use Windows process isolation. I will omit the details, but it seems that the behavior of Docker (maybe only compose) is slightly different between the two, so I was addicted to the restart setting.
Enable docker-compose restart settings in the Windows Server container.
OS:Windows Server 2019 Datacenter
Docker has a restart option that allows you to set whether to start the container when the machine starts, but even if you ported docker-compose.yml that worked in the Linux environment to the Windows Server container as it is, it could not be restarted successfully.
When I checked the operating status around Docker at startup and restart, it turned out that the default network enabled when docker-compose was started disappeared at restart.
It was solved by creating the network setting with nat external.
version: '3.5'
networks:
default:
external:
name: "nat"
services:
hoge:
build:
context: .
dockerfile: ./hoge/Dockerfile
container_name: hoge
restart: always
command: powershell
stdin_open: true
volumes:
- .\hoge:C:\hogehoge
If you're in trouble, it's best to look at the official Microsoft documentation (https://docs.microsoft.com/en-us/virtualization/windowscontainers/).
The content of this article is my personal opinion, not the official opinion of the organization to which I belong. The author and the organization to which he belongs cannot be held responsible for any troubles that may occur to users or third parties after implementing the contents of this article.
Recommended Posts