Mixing Windows and Linux containers via docker-compose on a Windows host - docker

I'm facing problems trying to mix Windows and Linux containers via docker-compose on a Windows host as demonstrated in https://devblogs.microsoft.com/premier-developer/mixing-windows-and-linux-containers-with-docker-compose/.
I cloned the original repository of the article (https://github.com/RandyPatterson/DockerComposeMultiPlatform) and already replaced each outdated base image from the Dockerfiles with the new links, you can see all relevant files below. I can get it to run manually by first switching to the Linux daemon, spinning up a container for the API, then switching to the Windows daemon and spinning up a container for the web app.
According to https://stackoverflow.com/a/72260359, docker-compose should also do this, including building it for the respective platform and when I run docker-compose up -d on the Windows daemon, it first starts fine by pulling the Linux images for the ApiTier Dockerfile until the first RUN line, where I then get the error hcsshim::CreateComputeSystem 186c82040b2e396b4b6e4c4063c2c8f562e855469630b82415e51043f6cb1773: An adapter was not found.
docker-compose.yml
version: '2.4'
services:
webtier:
image: webtier:win
platform: windows
ports:
- 80
build:
context: .\WebTier
dockerfile: Dockerfile
depends_on:
- apitier
environment:
ApiHost: "apitier"
apitier:
image: apitier:linux
platform: linux
expose:
- 80
build:
context: .\ApiTier
dockerfile: Dockerfile
ApiTier\Dockerfile
FROM mcr.microsoft.com/dotnet/aspnet:2.1 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:2.1 AS build
WORKDIR "/src/ApiTier"
COPY . .
RUN dotnet build "WebApi.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "WebApi.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebApi.dll"]
WebTier\Dockerfile
FROM mcr.microsoft.com/dotnet/framework/aspnet:4.7.2
WORKDIR /inetpub/wwwroot
COPY docker/ .
docker version
Client:
Cloud integration: v1.0.29
Version: 20.10.21
API version: 1.41
Go version: go1.18.7
Git commit: baeda1f
Built: Tue Oct 25 18:08:16 2022
OS/Arch: windows/amd64
Context: default
Experimental: true
Server: Docker Desktop 4.15.0 (93002)
Engine:
Version: 20.10.21
API version: 1.41 (minimum version 1.24)
Go version: go1.18.7
Git commit: 3056208
Built: Tue Oct 25 18:03:04 2022
OS/Arch: windows/amd64
Experimental: true
docker-compose version
docker-compose version 1.29.2, build 5becea4c
docker-py version: 5.0.0
CPython version: 3.9.0
OpenSSL version: OpenSSL 1.1.1g 21 Apr 2020
Docker daemon json for Windows
{
"experimental": true,
"features": {
"buildkit": false
}
}
Docker daemon json for Linux
{
"builder": {
"gc": {
"defaultKeepStorage": "20GB",
"enabled": true
}
},
"experimental": true,
"features": {
"buildkit": true
}
}

Steps first, details later:
Switch docker to use Windows containers
In the Docker engine, set experimental to true (I see its already true on your end).
select the "Use Docker Compose V2" in the docker settings (under General).
run the docker-compose up -d command.
The example repo you have shared failed to build on my side, but I found a better example, and it works(with some mods of course :) )
sample docker-compose.yml:
version: '3.8'
services:
nanoserver:
container_name: nanoserver
image: mcr.microsoft.com/windows/servercore/iis:windowsservercore-20H2
sql2017:
container_name: sql2017
platform: linux
mem_limit: 4GB
environment:
- ACCEPT_EULA=Y
- MSSQL_PID=Developer
- SA_PASSWORD=Mypass1.
ports:
- '1433:1433'
image: mcr.microsoft.com/mssql/server:2017-latest
I am using the same docker versions (server and client) as you. However, I think v2 of docker-compose is needed:
$ docker-compose version
Docker Compose version v2.13.0
Make sure to select the "Use Docker Compose V2" in the docker settings.
Refs:
Run Docker for Windows in “mixed” mode by running Windows and Linux containers together
How to enable mixed platform on Docker on year 2022?

Related

docker-compose context with remote ssh doens't work

I created a minimal docker-compose.yml file, something like this
version: '3.7'
services:
odoo:
image: odoo:14.0
container_name: odoo-app
restart: always
command:
--without-demo all
then create a new docker context using
sudo docker context create remote --docker "host=ssh://root#my-remote.server.com:2222"
i can see the new created context using
sudo docker context ls
i can connect to ssh without problem
When i try to run this deployment nothing happen
(venv) augusto#augusto-NUC10i7FNH:~/Progetti/odoo$ sudo docker-compose --verbose --context remote -f docker-compose.yml -f docker-compose.prod.yml up -d
compose.config.config.find: Using configuration files: ./docker-compose.yml,./docker-compose.prod.yml
(venv) augusto#augusto-NUC10i7FNH:~/Progetti/odoo$
why?
Both hosts (local and remote server) have Ubuntu 20.04 and the same version of docker-compose
docker-compose version 1.28.2, build unknown
docker-py version: 4.4.1
CPython version: 3.8.5
OpenSSL version: OpenSSL 1.1.1f 31 Mar 2020

How to run/host: Multiple environments on same machine with docker-compose

I am having 3 compose file overrides, for dev, QA, staging environments.
I have one server and there I have to host/run containers for QA and Staging environments (completely separately !!. separate containers, network, and volumes).
In each compose file overrides, I am having different volume names, network names, image names, container names, all controlled by environment-specific .env files.
When I run docker-compose -f "docker-compose.yml" -f "docker-compose.qa.yml" up -d, it creates QA environment images and runs containers having name QA in it.
When I run docker-compose -f "docker-compose.yml" -f "docker-compose.staging.yml" up -d, it creates Staging environment images and runs containers having name Staging in it.
but I am not able to run both simultaneously.
Port bindings are also controlled by .env files and are different for each environment.
(I am able to specify the .env file I have to use during docker-compose up command)
services:
service1:
networks:
- dev
volumes:
- "vol_service1:/some/path/to/container"
service2:
networks:
- dev
volumes:
- "vol_service2:/some/path/to/container"
service3:
networks:
- dev
volumes:
- "vol_service3:/some/path/to/container"
service4:
networks:
- dev
volumes:
- "vol_service4:/some/path/to/container"
networks:
dev:
driver:bridge
volumes:
vol_service1:
vol_service2:
vol_service3:
vol_service4:
I am using Docker for Windows, following are the details:
Client: Docker Engine - Community
Version: 18.09.2
API version: 1.39
Go version: go1.10.8
Git commit: 6247962
Built: Sun Feb 10 04:12:31 2019
OS/Arch: windows/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.2
API version: 1.39 (minimum version 1.12)
Go version: go1.10.6
Git commit: 6247962
Built: Sun Feb 10 04:13:06 2019
OS/Arch: linux/amd64
Experimental: false
That was really silly on my part. I missed out an important point in the documentation on docker-compose.
You need to specify COMPOSE_PROJECT_NAME environment variable, if not specified then it will pick up the folder name where your compose file resides.
Just name this environment variable differently for your environment and you are good to go.

How to change timezone on docker private registry running container?

How can I change timezone/time on my running docker private registry container
Host OS: CentOS 7
Docker Version:
Server:
Version: 17.09.0-ce
API version: 1.32 (minimum version 1.12)
Go version: go1.8.3
Git commit: afdb6d4
Built: Tue Sep 26 22:42:49 2017
OS/Arch: linux/amd64
Experimental: false
Docker registry image: registry:2 ID: a07e3f32a779
Tried execute on container:
export TZ=Europe/Warsaw
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
but without any result for real time.
Same solution works on another containers without any problems.
Any Ideas?
Edit:
Recreated container with compose like this:
apache:
image: "httpd:2.4"
hostname: deleted
restart: always
environment:
- TZ=Europe/Warsaw
ports:
- 5043:5043
links:
- registry:registry
volumes:
- /opt/docker-registry-bundle/auth:/usr/local/apache2/conf
- /etc/timezone:/etc/timezone:ro
registry:
image: registry:2
restart: always
environment:
- TZ=Europe/Warsaw
ports:
- 127.0.0.1:5000:5000
volumes:
- /opt/docker-registry-bundle/registry-data:/var/lib/registry
- /etc/timezone:/etc/timezone:ro
On apache container time is ok.
On registry container still doesn't work.
The following should work when executed inside container:
echo "Europe/Warsaw" > /etc/timezone
dpkg-reconfigure -f noninteractive tzdata
Solution from sanath
registry:2 image uses alpine base image because of that dpkg command
is missing, refer below link which explains how to change timezone in
alpine based images.
ivankrizsan.se/2015/10/31/time-in-docker-containers ( see Alpine Linux
section )

docker-compose oci runtime error executable file not found (in linked container)

I'm trying to setup docker & compose for running integration tests
I have the following docker-compose.yml
version: '3'
services:
tests:
build:
context: .
dockerfile: Dockerfile.tests
links:
- web
- maindb
web:
build:
context: .
dockerfile: Dockerfile.web
ports:
- "8080:8080"
volumes:
- .:/code
- logvolume01:/var/log
links:
- maindb
maindb:
image: postgres
environment:
POSTGRES_PASSWORD: example
volumes:
logvolume01: {}
web container itself works pretty fine
$ docker-compose -p wh run web
Starting wh_maindb_1 ... done
2017/07/27 22:05:34 [I] http server Running on http://:8080
But when I run tests container, I get the error
$ docker-compose -p wh run tests
Starting wh_maindb_1 ... done
Starting 6faff07f7671_6faff07f7671_wh_web_1 ...
Starting 6faff07f7671_6faff07f7671_wh_web_1 ... error
ERROR: for 6faff07f7671_6faff07f7671_wh_web_1 Cannot start service web: oci runtime error: container_linux.go:262: starting container process caused "exec: \"web\": executable file not found in $PATH"
Here is my Dockerfile.web
$ cat Dockerfile.web
FROM ubuntu:xenial
WORKDIR /app
ADD bin/* /app/
CMD ["/app/web"]
/app/web is dynamically linked daemon written in Golang 1.6
And some version info
$ docker version
Client:
Version: 17.06.0-ce
API version: 1.30
Go version: go1.8.3
Git commit: 02c1d87
Built: Fri Jun 23 21:23:31 2017
OS/Arch: linux/amd64
Server:
Version: 17.06.0-ce
API version: 1.30 (minimum version 1.12)
Go version: go1.8.3
Git commit: 02c1d87
Built: Fri Jun 23 21:19:04 2017
OS/Arch: linux/amd64
Experimental: false
$ docker-compose version
docker-compose version 1.14.0, build c7bdf9e
docker-py version: 2.4.2
CPython version: 2.7.12
OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016
This is maybe related to some docker-compose bug.
Try cleaning containers
docker-compose down
Alternatively this (you will lose your container data):
docker rm -f $(docker ps -a -q)

Docker compose error: compose.cli.main.main: Container command could not be invoked

I am trying to run haproxy in a docker container. To build and run the haproxy from the image, docker-compose reads my .yaml file below.
proxy:
build: ./
env_file: .env
ports:
- "8000:80"
- "9000:9000"
After executing a docker-compose build, the image is created but while trying to spawn a container using the following, I am getting the following errors:
$ docker-compose up -d
Starting my_haproxy_container
←[31mERROR←[0m: Container command could not be invoked.
By docker install information:
$ docker version
Client:
Version: 1.10.2
API version: 1.22
Go version: go1.5.3
Git commit: c3959b1
Built: Mon Feb 22 22:37:33 2016
OS/Arch: windows/amd64
Server:
Version: 1.10.3
API version: 1.22
Go version: go1.5.3
Git commit: 20f81dd
Built: Thu Mar 10 21:49:11 2016
OS/Arch: linux/amd64
I am not sure why the docker-compose up -d is unable to bring up the container. Any information is much appreciated. Thank you.
Container command could not be invoked
Is means you have problems with CMD in your Dockerfile. It is not docker-compose problem.
Incorrect CMD command
Command in CMD tries to run file without -execute permission
Check you ./Dockerfile

Resources