2

I can't get to azure container instance linked a file from my docker to a file that I placed in an azure storage account

the path after the volume name does not seem to be accepted : /conf/nginx.conf

volumes:
  - nginxconf/conf/nginx.conf:/etc/nginx/nginx.conf

here is my docker-compose.yml

version: '3.9'

services:
  client:
    image: nginx
    ports:
      - '8080:80'
    volumes:
      - nginxconf/conf/nginx.conf:/etc/nginx/nginx.conf

volumes:
  nginxconf:
    driver: azure_file
    driver_opts:
      share_name: nginxfiles
      storage_account_name: nginxcontainerstorage
      storage_account_key: "xxxxxxxxxxxxxxx"


Philippe Auriou
  • 567
  • 4
  • 17

2 Answers2

2

to solve my problem I modified the systemctl service file to launch nginx by specifying a configuration file in a different location. and I have a volume where there is the nginx.service and another with my nginx configuration. I mount folders and not a file and it works

my code : https://github.com/auriou/dockerfiles/tree/master/nginx

I had done the test locally and then on azure

Local :

version: '3.9'

services:
  client:
    image: nginx
    ports:
      - '8080:80'
    volumes:
      - nginxconfig:/etc/nginx/myconfig
      - nginxservice:/etc/systemd/system/multi-user.target.wants

volumes:
  nginxconfig:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: "/mnt/c/Users/p.auriou/Documents/GIT/azure/aci/nginx/docker/config"
  nginxservice:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: "/mnt/c/Users/p.auriou/Documents/GIT/azure/aci/nginx/docker/service"

azure: I copied the files to my azure storage

version: '3.9'

services:
  client:
    image: nginx
    domainname: nginxconf
    ports:
      - '80:80'
    volumes:
      - nginxconfig:/etc/nginx/myconfig
      - nginxservice:/etc/systemd/system/multi-user.target.wants

volumes:
  nginxconfig:
    driver: azure_file
    driver_opts:
      share_name: nginxconfig
      storage_account_name: nginxcontainerstorage
      storage_account_key: "XXXXXXXXXXX"
  nginxservice:
    driver: azure_file
    driver_opts:
      share_name: nginxservice
      storage_account_name: nginxcontainerstorage
      storage_account_key: "XXXXXXXXXXX"


The systemd file for nginx

[Unit]
Description=nginx - high performance web server
Documentation=https://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStart=/usr/sbin/nginx -c /etc/nginx/myconfig/nginx.conf
ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /var/run/nginx.pid)"
ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /var/run/nginx.pid)"

[Install]
WantedBy=multi-user.target
Philippe Auriou
  • 567
  • 4
  • 17
0

I have tried to reproduce the same in my environment and got the positive results.

Note: In this demo, I have tried to bind index.html file to /usr/share/nginx/html folder to identify the changes easily.

Step 1: Add docker context to run docker-compose.yaml in ACI

enter image description here
Refer to this link for more information on setting docker context.

To repro your issue, I have executed docker-compose.yaml file with below configuration as like yours.

enter image description here

I got the below error after running the above code.

enter image description here

Now, I have modified the above code as below.

enter image description here

version: '3.9'

services:
  client:
    image: nginx
    ports:
      - '80:80'
    volumes:
      - nginxconf:/usr/share/nginx/html

volumes:
  nginxconf:
    driver: azure_file
    driver_opts:
      share_name: fileshare4dc
      storage_account_name: strg4dc
      storage_account_key: "xxxxxxxxxxxxxxxxxxxxxxxxx"

Note: ACI does not support port mapping as of now. Container port and ACI port must be same.

Now run docker compose and verify the container instance created.

$docker compose --project-name nginx-aci up -d

enter image description here

enter image description here

Compare the files in azure file share and ACI to check bind volume is working properly or not.

Below are the files in my Azure fileshare.

enter image description here

Below are the files in my Container.

enter image description here
Commands used in above screenshot.

$docker ps
$docker exec -it <container-name> bash

Whatever changes or files adding in Azure file share, it will reflect same in container.

HowAreYou
  • 605
  • 2
  • 6
  • yes it works but it doesn't solve my problem. In your case you linked a folder and in my case it's a file I want linked. Because in the directory containing /etc/nginx/nginx.conf contains other files. So we can't link the complete folder /etc/nginx/ – Philippe Auriou Mar 09 '23 at 13:05
  • Two questions for you. (1) Where did you get the plugin `azure_file`? (2) [docker Office document](https://docs.docker.com/cloud/aci-integration/) said, Docker Compose’s integration for ECS and ACI is retiring in November 2023. Any other solutions? – Bill Jul 05 '23 at 09:14