i’m trying to run two services into two different containers, both connected in a volume.
This is the docker-compose.yml:
version: "3"
services:
db:
build:
context: db
volumes:
- donazioni-vol:/var/lib/mysql
env_file:
- config.env
generatore:
build:
context: generatore
env_file:
- config.env
depends_on:
- db
volumes:
donazioni-vol:
By the way, when i launch the docker-compose up --build
cmd, at the end i find only one container started (solidarieta_db)
To start solidarieta_generatore, i have to use this command:
sudo docker container run -d --network=solidarieta_default --env-file=config.env -v solidarieta_donazioni-vol:/var/lib/mysql solidarieta_generatore
because apparently this container is unable to load the .env file, nor to connect to the same network as the other container, nor to point to the same volume, despite all this being specified in the docker-compose.yml. And this is my problem.
Even after executing this command, doing an inspect of the container, I get this output, where on Volume there is null. How can I solve it? Where am I doing wrong?
[
{
"Id": "90cb0bcb94f21e5dd811e4d5b7fe5e599b9bc921b622001aa4ba136e9e67dc81",
"Created": "2024-05-08T20:36:03.076150753Z",
"Path": "python",
"Args": [
"script.py"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 15630,
"ExitCode": 0,
"Error": "",
"StartedAt": "2024-05-08T20:36:03.288837462Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:3754f25acdbbc4cd58eea56c63ab6baac5640e909bdb68f7f84d18691be44cda",
"ResolvConfPath": "/var/lib/docker/containers/90cb0bcb94f21e5dd811e4d5b7fe5e599b9bc921b622001aa4ba136e9e67dc81/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/90cb0bcb94f21e5dd811e4d5b7fe5e599b9bc921b622001aa4ba136e9e67dc81/hostname",
"HostsPath": "/var/lib/docker/containers/90cb0bcb94f21e5dd811e4d5b7fe5e599b9bc921b622001aa4ba136e9e67dc81/hosts",
"LogPath": "/var/lib/docker/containers/90cb0bcb94f21e5dd811e4d5b7fe5e599b9bc921b622001aa4ba136e9e67dc81/90cb0bcb94f21e5dd811e4d5b7fe5e599b9bc921b622001aa4ba136e9e67dc81-json.log",
"Name": "/hopeful_johnson",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": [
"solidarieta_donazioni-vol:/var/lib/mysql"
],
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "solidarieta_default",
"PortBindings": {},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"ConsoleSize": [
30,
120
],
"CapAdd": null,
"CapDrop": null,
"CgroupnsMode": "host",
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "private",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": [],
"BlkioDeviceWriteBps": [],
"BlkioDeviceReadIOps": [],
"BlkioDeviceWriteIOps": [],
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DeviceRequests": null,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": null,
"Ulimits": [],
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": [
"/proc/asound",
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware",
"/sys/devices/virtual/powercap"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/a9476a464bb11678e399a70e234670e6ed692e8e75b2769b67b1944cd7e01bfd-init/diff:/var/lib/docker/overlay2/f970a9b553b247ee5a378d3b012e7257583d8ed535893934896dc3d1701598e8/diff:/var/lib/docker/overlay2/6422856fe380d309e78ec47c0722003cc6be4ccdd094af58df3272056c3eabc1/diff:/var/lib/docker/overlay2/0fda3cdce7af987aab5ba84053895872c28b7c00318f5cb72f7b428febcfabc7/diff:/var/lib/docker/overlay2/1ef09319339ff7853bc0d31953d6d78ca5eba7be0bdc6397158cd2f0534fe31d/diff:/var/lib/docker/overlay2/cde98e05aa6c12e46655f61dc0622cd1f515c53fba129e6c83b7f7c782e9eb01/diff:/var/lib/docker/overlay2/e3d88db9f89e28c922ddf963a274a64f7044066f863eca89b867ef5caf8f70ff/diff:/var/lib/docker/overlay2/4f64af71e6ba385f87142ead181523e24a9effb464412f3834da7f31c56d6c87/diff:/var/lib/docker/overlay2/a35d039c3b882dec5121765583c14a5b1adcce82ceb9d1927208e7a3742601ce/diff",
"MergedDir": "/var/lib/docker/overlay2/a9476a464bb11678e399a70e234670e6ed692e8e75b2769b67b1944cd7e01bfd/merged",
"UpperDir": "/var/lib/docker/overlay2/a9476a464bb11678e399a70e234670e6ed692e8e75b2769b67b1944cd7e01bfd/diff",
"WorkDir": "/var/lib/docker/overlay2/a9476a464bb11678e399a70e234670e6ed692e8e75b2769b67b1944cd7e01bfd/work"
},
"Name": "overlay2"
},
"Mounts": [
{
"Type": "volume",
"Name": "solidarieta_donazioni-vol",
"Source": "/var/lib/docker/volumes/solidarieta_donazioni-vol/_data",
"Destination": "/var/lib/mysql",
"Driver": "local",
"Mode": "z",
"RW": true,
"Propagation": ""
}
],
"Config": {
"Hostname": "90cb0bcb94f2",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": true,
"OpenStdin": true,
"StdinOnce": false,
"Env": [
"MYSQL_USER=dockerdev",
"MYSQL_PASSWORD=topolino",
"MYSQL_ROOT_PASSWORD=topolino",
"MYSQL_DATABASE=solidarieta",
"PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"LANG=C.UTF-8",
"GPG_KEY=7169605F62C751356D054A26A821E680E5FA6305",
"PYTHON_VERSION=3.12.3",
"PYTHON_PIP_VERSION=24.0",
"PYTHON_GET_PIP_URL=https://github.com/pypa/get-pip/raw/dbf0c85f76fb6e1ab42aa672ffca6f0a675d9ee4/public/get-pip.py",
"PYTHON_GET_PIP_SHA256=dfe9fd5c28dc98b5ac17979a953ea550cec37ae1b47a5116007395bfacff2ab9"
],
"Cmd": [
"python",
"script.py"
],
"Image": "solidarieta_generatore",
"Volumes": null,
"WorkingDir": "/app",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "a9f30df46590da5c51669037421179ad39a800f6f500d501e9552c975eca4659",
"SandboxKey": "/var/run/docker/netns/a9f30df46590",
"Ports": {},
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"solidarieta_default": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"MacAddress": "02:42:ac:13:00:03",
"NetworkID": "a50885a79891a72cdd1ac8b375a4051aa1586f90590c6fc8c479a41568f4b045",
"EndpointID": "a3bf6f591a905317accc8b6fe61c227f64075fb0c6ee77758704914896b11581",
"Gateway": "172.19.0.1",
"IPAddress": "172.19.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"DriverOpts": null,
"DNSNames": [
"hopeful_johnson",
"90cb0bcb94f2"
]
}
}
}
}
]
Thanks in advice.
fpally_dev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.