Let's say I want to create two services:
The first one on port 5000
The second one on port 7000
So I create docker-compose.yml file
version: "3"
services:
project-server:
build: .
ports:
- "5000:5000"
environment:
- PORT=5000
depends_on:
- mongo
project-socket-server:
build:
context: "."
dockerfile: "./Dockerfile-socket"
ports:
- "7000:7000"
environment:
- PORT=7000
depends_on:
- project-server
mongo:
image: mongo
environment:
- MONGO_INITDB_ROOT_USERNAME=project_admin
- MONGO_INITDB_ROOT_PASSWORD=9293
volumes:
- mongo-db:/data/db
volumes:
mongo-db:
and docker-compose.dev.yml
version: "3"
services:
project-server:
build:
context: .
args:
NODE_ENV: development
volumes:
- .:/server
- /server/node_modules
environment:
- NODE_ENV=development
- MONGO_USER=project_admin
- MONGO_PASSWORD=9293
command: npm run dev
project-socket-server:
build:
context: "."
dockerfile: "./Dockerfile-socket"
args:
NODE_ENV: development
volumes:
- .:/server
- /server/node_modules
environment:
- NODE_ENV=development
- MONGO_USER=project_admin
- MONGO_PASSWORD=9293
command: npm run dev
mongo:
environment:
- MONGO_INITDB_ROOT_USERNAME=project_admin
- MONGO_INITDB_ROOT_PASSWORD=9293
Dockerfile - for the first service
FROM node:15
WORKDIR /server
COPY package.json .
RUN npm install --only=production
ARG NODE_ENV
RUN if [ "$NODE_ENV" = "development" ]; \
then npm install; \
else npm install --only=production; \
fi
COPY . ./
EXPOSE 5000
CMD ["node", "index.js"]
And Dockerfile-socket for the second service
FROM node:15
WORKDIR /server
COPY package.json .
RUN npm install --only=production
ARG NODE_ENV
RUN if [ "$NODE_ENV" = "development" ]; \
then npm install; \
else npm install --only=production; \
fi
COPY . ./
EXPOSE 7000
CMD ["node", "server.js"]
And package.json as well:
{
"name": "project-server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon index.js && nodemon server.js",
"dev": "nodemon index.js && nodemon server.js"
},
"dependencies": {
"#socket.io/mongo-adapter": "^0.2.1",
"cookie-parser": "^1.4.6",
"express": "^4.18.1",
"mongodb": "^4.6.0",
"mongoose": "^6.3.2",
"nodemailer": "^6.7.5",
"socket.io": "^4.5.1",
"stripe": "^9.11.0",
"ws": "^8.6.0"
},
"devDependencies": {
"nodemon": "^2.0.16"
}
}
The problem is, after I call docker-compose the both containers will start - there is no problem here, as I call localhost:5000, it gives me correct data, but after I call localhost:7000 I see all the data as if I call localhost:5000. Am I doing something wrong?
UPD:
it looks like on port 7000 starts index.js, and not server.js script
index.js file:
const port = process.env.PORT;
console.log("connected to port index " + port);
gives back:
connected to port index 5000
server.js file:
const port = process.env.PORT;
console.log("connected to port server " + port);
gives back:
connected to port index 7000
UPD2:
inspect port 5000:
[
{
"Id": "6a7729ba9734df523fc7424221d866a63a83faec716f6c7efbf77a3797ff9a51",
"Created": "2022-07-10T16:01:57.4280865Z",
"Path": "docker-entrypoint.sh",
"Args": [
"npm",
"run",
"dev"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 29648,
"ExitCode": 0,
"Error": "",
"StartedAt": "2022-07-10T16:01:58.2066126Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:797d9993a50984ae392476eb54bf79014011d6f146c6b9f2b2f4d46bb6ecdf20",
"ResolvConfPath": "/var/lib/docker/containers/6a7729ba9734df523fc7424221d866a63a83faec716f6c7efbf77a3797ff9a51/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/6a7729ba9734df523fc7424221d866a63a83faec716f6c7efbf77a3797ff9a51/hostname",
"HostsPath": "/var/lib/docker/containers/6a7729ba9734df523fc7424221d866a63a83faec716f6c7efbf77a3797ff9a51/hosts",
"LogPath": "/var/lib/docker/containers/6a7729ba9734df523fc7424221d866a63a83faec716f6c7efbf77a3797ff9a51/6a7729ba9734df523fc7424221d866a63a83faec716f6c7efbf77a3797ff9a51-json.log",
"Name": "/project-server_project-server_1",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": [
"/Users/nikita/Desktop/project-server:/server:rw"
],
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "project-server_default",
"PortBindings": {
"5000/tcp": [
{
"HostIp": "",
"HostPort": "5000"
}
]
},
"RestartPolicy": {
"Name": "",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": [],
"CapAdd": null,
"CapDrop": null,
"CgroupnsMode": "private",
"Dns": null,
"DnsOptions": null,
"DnsSearch": null,
"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",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": null,
"DeviceCgroupRules": null,
"DeviceRequests": null,
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": null,
"PidsLimit": null,
"Ulimits": null,
"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"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/cb1f731b1d50d3ecb220dd8769e1e9088d501429a7760b23474b40fb2baae477-init/diff:/var/lib/docker/overlay2/z2db8ueu6gzx4g6kml9gm4lqh/diff:/var/lib/docker/overlay2/4a5siyd2j04hfi7shvk5uyen8/diff:/var/lib/docker/overlay2/je4ef30hthjwlgjf41mrz7c6p/diff:/var/lib/docker/overlay2/o1n9ak157b8zru8l8zip2oiwu/diff:/var/lib/docker/overlay2/dbdi66mhdlurq8ljn2p8gnotx/diff:/var/lib/docker/overlay2/30480c3ac46a01c8279f265b8055162c1c628ed901b2fa5f13a481933fb6acf2/diff:/var/lib/docker/overlay2/18eb589f35db055e79336c54cc0e5da75d5fed390e4ef3edc149767578e4d304/diff:/var/lib/docker/overlay2/1f82814e597da8a6eef3b98677f9a00eda7ca517b3413fcc43de663692a522b2/diff:/var/lib/docker/overlay2/68e13aa159454b660beda0b20784243a29422d1e67c76a4043d485d2f2bf7fc2/diff:/var/lib/docker/overlay2/3befd14aea9bb18d7ba0fd5aecc2205420fc373fa70b99d93ce1c85de6434fc0/diff:/var/lib/docker/overlay2/85a4d0b611d3d1cd423a78a68cdede7193f8665fef0cfdf573e849abdf32aa08/diff:/var/lib/docker/overlay2/3ee2ce61fd86f7d3eee34d744dfc313068ed76c3a1df068db9d3614c1c4626d5/diff:/var/lib/docker/overlay2/785dcc56e0a473c70c3a8b19b2a163c729fe43c8a2cf8f1a17afc30af0b6a81c/diff:/var/lib/docker/overlay2/a3d6650199856fc04ea61fb1936888adc9324b19fd8ec60f19445bc2fafed8ac/diff",
"MergedDir": "/var/lib/docker/overlay2/cb1f731b1d50d3ecb220dd8769e1e9088d501429a7760b23474b40fb2baae477/merged",
"UpperDir": "/var/lib/docker/overlay2/cb1f731b1d50d3ecb220dd8769e1e9088d501429a7760b23474b40fb2baae477/diff",
"WorkDir": "/var/lib/docker/overlay2/cb1f731b1d50d3ecb220dd8769e1e9088d501429a7760b23474b40fb2baae477/work"
},
"Name": "overlay2"
},
"Mounts": [
{
"Type": "bind",
"Source": "/Users/nikita/Desktop/project-server",
"Destination": "/server",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
},
{
"Type": "volume",
"Name": "54ae173b93a965d9ac3feba255694b31718c684026fb05fc5d811de873319ebf",
"Source": "/var/lib/docker/volumes/54ae173b93a965d9ac3feba255694b31718c684026fb05fc5d811de873319ebf/_data",
"Destination": "/server/node_modules",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
],
"Config": {
"Hostname": "6a7729ba9734",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"5000/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PORT=5000",
"NODE_ENV=development",
"MONGO_USER=project_admin",
"MONGO_PASSWORD=9293",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"NODE_VERSION=15.14.0",
"YARN_VERSION=1.22.5"
],
"Cmd": [
"npm",
"run",
"dev"
],
"Image": "project-server_project-server",
"Volumes": {
"/server": {},
"/server/node_modules": {}
},
"WorkingDir": "/server",
"Entrypoint": [
"docker-entrypoint.sh"
],
"OnBuild": null,
"Labels": {
"com.docker.compose.config-hash": "3ac7f110d763362d49938c1ed5213e7e50072c8ab95ee0b8c58f9dc2826d9ae6",
"com.docker.compose.container-number": "1",
"com.docker.compose.oneoff": "False",
"com.docker.compose.project": "project-server",
"com.docker.compose.project.config_files": "docker-compose.yml,docker-compose.dev.yml",
"com.docker.compose.project.working_dir": "/Users/nikita/Desktop/project-server",
"com.docker.compose.service": "project-server",
"com.docker.compose.version": "1.29.2"
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "ebc830dec3ca4c02819e90f2fa79b0db8f88043ba56abb67795bb510fba14ad4",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"5000/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "5000"
}
]
},
"SandboxKey": "/var/run/docker/netns/ebc830dec3ca",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"project-server_default": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"project-server",
"6a7729ba9734"
],
"NetworkID": "3f5807c2c3187687876240b47feb4fd5e997c561dbef6462fd3a195ad0b11f43",
"EndpointID": "2ccabd2ce6680746c69b9dfd03b85cf17fe9fea4d614ffc58e2e4b74e1eec9a5",
"Gateway": "192.168.192.1",
"IPAddress": "192.168.192.3",
"IPPrefixLen": 20,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:c0:a8:c0:03",
"DriverOpts": null
}
}
}
}
]
inspect port 7000
[
{
"Id": "856312d4b656a689e54567e0c2f33319d7396e16c2d0927b003c4a204b6d58b4",
"Created": "2022-07-10T16:01:58.2531359Z",
"Path": "docker-entrypoint.sh",
"Args": [
"npm",
"run",
"dev"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 29787,
"ExitCode": 0,
"Error": "",
"StartedAt": "2022-07-10T16:01:58.6972426Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:d9831965ad489f691c2dedbdd5c12c4afc780322e43105add43f0db791d88362",
"ResolvConfPath": "/var/lib/docker/containers/856312d4b656a689e54567e0c2f33319d7396e16c2d0927b003c4a204b6d58b4/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/856312d4b656a689e54567e0c2f33319d7396e16c2d0927b003c4a204b6d58b4/hostname",
"HostsPath": "/var/lib/docker/containers/856312d4b656a689e54567e0c2f33319d7396e16c2d0927b003c4a204b6d58b4/hosts",
"LogPath": "/var/lib/docker/containers/856312d4b656a689e54567e0c2f33319d7396e16c2d0927b003c4a204b6d58b4/856312d4b656a689e54567e0c2f33319d7396e16c2d0927b003c4a204b6d58b4-json.log",
"Name": "/project-server_project-socket-server_1",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": [
"/Users/nikita/Desktop/project-server:/socket-server:rw"
],
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "project-server_default",
"PortBindings": {
"7000/tcp": [
{
"HostIp": "",
"HostPort": "7000"
}
]
},
"RestartPolicy": {
"Name": "",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": [],
"CapAdd": null,
"CapDrop": null,
"CgroupnsMode": "private",
"Dns": null,
"DnsOptions": null,
"DnsSearch": null,
"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",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": null,
"DeviceCgroupRules": null,
"DeviceRequests": null,
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": null,
"PidsLimit": null,
"Ulimits": null,
"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"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/f92796078a9effb55efa307514fcaea257d3ca5cfe1fa9717dd8f26eda800a8b-init/diff:/var/lib/docker/overlay2/z2db8ueu6gzx4g6kml9gm4lqh/diff:/var/lib/docker/overlay2/4a5siyd2j04hfi7shvk5uyen8/diff:/var/lib/docker/overlay2/je4ef30hthjwlgjf41mrz7c6p/diff:/var/lib/docker/overlay2/o1n9ak157b8zru8l8zip2oiwu/diff:/var/lib/docker/overlay2/dbdi66mhdlurq8ljn2p8gnotx/diff:/var/lib/docker/overlay2/30480c3ac46a01c8279f265b8055162c1c628ed901b2fa5f13a481933fb6acf2/diff:/var/lib/docker/overlay2/18eb589f35db055e79336c54cc0e5da75d5fed390e4ef3edc149767578e4d304/diff:/var/lib/docker/overlay2/1f82814e597da8a6eef3b98677f9a00eda7ca517b3413fcc43de663692a522b2/diff:/var/lib/docker/overlay2/68e13aa159454b660beda0b20784243a29422d1e67c76a4043d485d2f2bf7fc2/diff:/var/lib/docker/overlay2/3befd14aea9bb18d7ba0fd5aecc2205420fc373fa70b99d93ce1c85de6434fc0/diff:/var/lib/docker/overlay2/85a4d0b611d3d1cd423a78a68cdede7193f8665fef0cfdf573e849abdf32aa08/diff:/var/lib/docker/overlay2/3ee2ce61fd86f7d3eee34d744dfc313068ed76c3a1df068db9d3614c1c4626d5/diff:/var/lib/docker/overlay2/785dcc56e0a473c70c3a8b19b2a163c729fe43c8a2cf8f1a17afc30af0b6a81c/diff:/var/lib/docker/overlay2/a3d6650199856fc04ea61fb1936888adc9324b19fd8ec60f19445bc2fafed8ac/diff",
"MergedDir": "/var/lib/docker/overlay2/f92796078a9effb55efa307514fcaea257d3ca5cfe1fa9717dd8f26eda800a8b/merged",
"UpperDir": "/var/lib/docker/overlay2/f92796078a9effb55efa307514fcaea257d3ca5cfe1fa9717dd8f26eda800a8b/diff",
"WorkDir": "/var/lib/docker/overlay2/f92796078a9effb55efa307514fcaea257d3ca5cfe1fa9717dd8f26eda800a8b/work"
},
"Name": "overlay2"
},
"Mounts": [
{
"Type": "bind",
"Source": "/Users/nikita/Desktop/project-server",
"Destination": "/socket-server",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
},
{
"Type": "volume",
"Name": "7a7d8d6a4c7c004640e16bc4f50be2f9b2cfb94855ebbf864999d5f8a263aa54",
"Source": "/var/lib/docker/volumes/7a7d8d6a4c7c004640e16bc4f50be2f9b2cfb94855ebbf864999d5f8a263aa54/_data",
"Destination": "/socket-server/node_modules",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
],
"Config": {
"Hostname": "856312d4b656",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"7000/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PORT=7000",
"NODE_ENV=development",
"MONGO_USER=project_admin",
"MONGO_PASSWORD=9293",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"NODE_VERSION=15.14.0",
"YARN_VERSION=1.22.5"
],
"Cmd": [
"npm",
"run",
"dev"
],
"Image": "project-server_project-socket-server",
"Volumes": {
"/socket-server": {},
"/socket-server/node_modules": {}
},
"WorkingDir": "/server",
"Entrypoint": [
"docker-entrypoint.sh"
],
"OnBuild": null,
"Labels": {
"com.docker.compose.config-hash": "1b0d7e398115bad6eae26e92b1d54d15163ca74e7f6570492daf14f023014052",
"com.docker.compose.container-number": "1",
"com.docker.compose.oneoff": "False",
"com.docker.compose.project": "project-server",
"com.docker.compose.project.config_files": "docker-compose.yml,docker-compose.dev.yml",
"com.docker.compose.project.working_dir": "/Users/nikita/Desktop/project-server",
"com.docker.compose.service": "project-socket-server",
"com.docker.compose.version": "1.29.2"
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "fe3cffcd72a06aaa92c87cd94280ce914bc13f7e269c51a98901ce639ba4a4d1",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"7000/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "7000"
}
]
},
"SandboxKey": "/var/run/docker/netns/fe3cffcd72a0",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"project-server_default": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"project-socket-server",
"856312d4b656"
],
"NetworkID": "3f5807c2c3187687876240b47feb4fd5e997c561dbef6462fd3a195ad0b11f43",
"EndpointID": "bd3915089cf996887646b20d34386214eca5ea484daa74284c5e1a63c144c3bd",
"Gateway": "192.168.192.1",
"IPAddress": "192.168.192.4",
"IPPrefixLen": 20,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:c0:a8:c0:04",
"DriverOpts": null
}
}
}
}
]
According to the docker containers inspect output you provided it seems you are running the following command:
"Path": "docker-entrypoint.sh",
"Args": [
"npm",
"run",
"dev"
],
"Cmd": [
"npm",
"run",
"dev"
]
in both of them, which is consistent with the command you provided for both containers in your docker-compose.dev.yml file:
command: npm run dev
As stated in the docker-compose documentation, please, be aware that by doing so you are overwriting your containers Dockerfile command.
It means that both containers are running the dev scripts.
According to your project structure it turns out both containers are sharing the same package.json and code.
In package.json you defined the dev script like this:
"scripts": {
"start": "nodemon index.js && nodemon server.js",
"dev": "nodemon index.js && nodemon server.js"
},
It means you are launching in both containers index.js, with different ports, according to your PORT variables declaration in each container, but they are both running index.js after all.
That explains why you are getting the same output in every call:
connected to port index ...
Although my advice is that you separate the source code for every container, to solve the problem you could try running a different script per every container. I mean, in your package.json file I would include a new script, server, for example:
"scripts": {
"start": "nodemon index.js && nodemon server.js",
"dev": "nodemon index.js",
"server": "nodemon server.js"
},
And use the new script when launching your container in docker-compose:
project-socket-server:
build:
context: "."
dockerfile: "./Dockerfile-socket"
args:
NODE_ENV: development
volumes:
- .:/server
- /server/node_modules
environment:
- NODE_ENV=development
- MONGO_USER=project_admin
- MONGO_PASSWORD=9293
command: npm run server
As an alternative, you can remove the lines:
command: npm run dev
from your docker-compose.dev.yml file:
ersion: "3"
services:
project-server:
build:
context: .
args:
NODE_ENV: development
volumes:
- .:/server
- /server/node_modules
environment:
- NODE_ENV=development
- MONGO_USER=project_admin
- MONGO_PASSWORD=9293
project-socket-server:
build:
context: "."
dockerfile: "./Dockerfile-socket"
args:
NODE_ENV: development
volumes:
- .:/server
- /server/node_modules
environment:
- NODE_ENV=development
- MONGO_USER=project_admin
- MONGO_PASSWORD=9293
mongo:
environment:
- MONGO_INITDB_ROOT_USERNAME=project_admin
- MONGO_INITDB_ROOT_PASSWORD=9293
This will make docker to use the CMD provided in the different Dockerfiles:
CMD ["node", "index.js"]
and:
CMD ["node", "server.js"]
which I think it will work as well.
As I said, please, consider in any case reorder your project structure to avoid using the same directory for building your two apps, as you can see it could be the cause of several problems.
As mentioned in "Putting Your NodeJS App in a Docker Container"
EXPOSE is a little different from the other instructions in that it doesn't have a practical purpose.
It only exists to provide metadata about what port the container expects to expose.
You don't need to use EXPOSE in your container, but anyone who has to understand how to connect to it will appreciate it.
You need to check if CMD ["node", "server.js"] in Dockerfile-socket does take advantage at runtime of the project-socket-server service environment: PORT=7000.
It uses the socketio/socket.io-mongo-adapter, which could use the port of the existing MongoDB it adapts to.
As discussed with the OP, and detailed jccampanero's more accurate answer, the root cause is the common package.json, with the common dev directive starting both index.js (first) and then server.js.
The first (index.js) would answer the query even though it is in the server container.
Related
ASP dotnet core web app container running but not opening in browser. using .net 6.0
i tried http://localhot
container port. please let me know where i am doing mistake.
Below i am sharing my Dockerfile and docker inpect result.
#workdir consider in app folder
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
WORKDIR /app
#restoring nuget package for csproj files
COPY *.csproj ./
RUN dotnet restore
#copy all project files
COPY . ./
RUN dotnet publish -c Release -o out
#creating running image
FROM mcr.microsoft.com/dotnet/sdk:6.0
WORKDIR /app
COPY --from=build-env /app/out/ .
EXPOSE 80
ENTRYPOINT ["dotnet","dotnetpracticeapp2.dll"]
Docker container inspect output
11:11
my dotnet core web .net 6.0 version Container is running but not opening in browser,here is my some details
#workdir consider in app folder
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
WORKDIR /app
#restoring nuget package for csproj files
COPY *.csproj ./
RUN dotnet restore
#copy all project files
COPY . ./
RUN dotnet publish -c Release -o out
#creating running image
FROM mcr.microsoft.com/dotnet/sdk:6.0
WORKDIR /app
COPY --from=build-env /app/out/ .
EXPOSE 80
ENTRYPOINT ["dotnet","dotnetpracticeapp2.dll"]
Docker container inspect output
{
"Id": "9fc1f41590c7e25ddd5ec66c542afac89c00ee9cef9c5148368f39c8a04248ce",
"Created": "2022-03-11T17:24:11.7749279Z",
"Path": "dotnet",
"Args": [
"dotnetpracticeapp2.dll"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 1304,
"ExitCode": 0,
"Error": "",
"StartedAt": "2022-03-12T18:00:28.6816882Z",
"FinishedAt": "2022-03-12T17:55:41.1098514Z"
},
"Image": "sha256:7d342807b790f1c7a2470db3ae47a85849bd8354939c3e4659a24d1ee388799f",
"ResolvConfPath": "/var/lib/docker/containers/9fc1f41590c7e25ddd5ec66c542afac89c00ee9cef9c5148368f39c8a04248ce/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/9fc1f41590c7e25ddd5ec66c542afac89c00ee9cef9c5148368f39c8a04248ce/hostname",
"HostsPath": "/var/lib/docker/containers/9fc1f41590c7e25ddd5ec66c542afac89c00ee9cef9c5148368f39c8a04248ce/hosts",
"LogPath": "/var/lib/docker/containers/9fc1f41590c7e25ddd5ec66c542afac89c00ee9cef9c5148368f39c8a04248ce/9fc1f41590c7e25ddd5ec66c542afac89c00ee9cef9c5148368f39c8a04248ce-json.log",
"Name": "/dotnetapp2",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {
"80/tcp": [
{
"HostIp": "",
"HostPort": "80"
}
]
},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"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",
"ConsoleSize": [
16,
125
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DeviceRequests": null,
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": null,
"Ulimits": null,
"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"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/5c6af7c62a17860faa1bccd6d57b064bc9639fbdc06dc200f12c63f0743fb0b7-init/diff:/var/lib/docker/overlay2/2fgcm3ps2hi5wuzj4nmid1gj4/diff:/var/lib/docker/overlay2/7g09cyks1ftmankkfn8rytjea/diff:/var/lib/docker/overlay2/43fbef426074496a5423ec4f2423857878095a252a5091db78cfe891af95ed3d/diff:/var/lib/docker/overlay2/dbf0cc5fcf1324ccac8470143b6b87a313e4df9a9aa344a9e600c968afcafa16/diff:/var/lib/docker/overlay2/41d81ab7ea010ecb9fac87a3b63d7183228ffc286bb2063690e5f7169f212d20/diff:/var/lib/docker/overlay2/3ee4f5439a2a5103f23ade1cde12fcf6ca386e1f2affbbd9337769ef1ef0ecd4/diff:/var/lib/docker/overlay2/15bdfbb6aecdf14bbe0b554c229ef08c4bd578c0ac2c6c002c419344d198df1a/diff:/var/lib/docker/overlay2/f8e7d9c155d0f25cd0076112aa911496febe9ca4e7a9ace2bf7a09b80f0c0bd5/diff:/var/lib/docker/overlay2/e1c521705e01879f23dadea31f56fb5ad6693acc5ddacec190216556cb8ba742/diff:/var/lib/docker/overlay2/095c04af29c37be9e84dbba0d0b7aadf6c0c91fbeca2a2fa1843815b0ebf9cd0/diff",
"MergedDir": "/var/lib/docker/overlay2/5c6af7c62a17860faa1bccd6d57b064bc9639fbdc06dc200f12c63f0743fb0b7/merged",
"UpperDir": "/var/lib/docker/overlay2/5c6af7c62a17860faa1bccd6d57b064bc9639fbdc06dc200f12c63f0743fb0b7/diff",
"WorkDir": "/var/lib/docker/overlay2/5c6af7c62a17860faa1bccd6d57b064bc9639fbdc06dc200f12c63f0743fb0b7/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "9fc1f41590c7",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"80/tcp": {}
},
"Tty": true,
"OpenStdin": true,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"ASPNETCORE_URLS=",
"DOTNET_RUNNING_IN_CONTAINER=true",
"DOTNET_VERSION=6.0.3",
"ASPNET_VERSION=6.0.3",
"Logging__Console__FormatterName=",
"DOTNET_GENERATE_ASPNET_CERTIFICATE=false",
"DOTNET_NOLOGO=true",
"DOTNET_SDK_VERSION=6.0.201",
"DOTNET_USE_POLLING_FILE_WATCHER=true",
"NUGET_XMLDOC_MODE=skip",
"POWERSHELL_DISTRIBUTION_CHANNEL=PSDocker-DotnetSDK-Debian-11"
],
"Cmd": null,
"Image": "parshchakurkar/dotnetapp:1.21",
"Volumes": null,
"WorkingDir": "/app",
"Entrypoint": [
"dotnet",
"dotnetpracticeapp2.dll"
],
"OnBuild": null,
"Labels": {}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "1788646d554f21bfed7a1c0be2c884f136bd7095aee00b10f36f1ce155225bc6",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"80/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "80"
},
{
"HostIp": "::",
"HostPort": "80"
}
]
},
"SandboxKey": "/var/run/docker/netns/1788646d554f",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "53d78ef8e764106367138ca777d419035a03219570a0a523875cf7157a8cd299",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "464a5c9c0dcba8adc13abe8ef9c2d4756a4b1525a92bfe643b4e2ef75b609d57",
"EndpointID": "53d78ef8e764106367138ca777d419035a03219570a0a523875cf7157a8cd299",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
}
}
}
please check and update where i am doing mistake
I presume docker command "docker run --rm -it -p 80:80 image ID"
Map port 80 on the local machine to port 80 in the container.
Please in the Internet browser key http://localhost: you build port 80 (EXPOSE 80)
if is in dockerfile add ENV ASPNETCORE_URLS=http://+:80
Please in the Internet browser key http://0.0.0.0:80/
Reference:https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/docker/building-net-docker-images?view=aspnetcore-6.0
I have an error that only happens when I run docker compose up on one of my docker compose files and not the other, even though the services named "proxy" in which the error occurs are identical.
When I run docker compose -f docker-compose-v1.yml up -d the containers start without issue but on inspection the container named github_proxy_1 has no mounts.
If I run docker-compose -f docker-compose-v2.yml up -d the containers start without issue and on inspection the container named github_proxy_1 has mounts.
The proxy services are based on traefik windows images. I have read that many have had issues with binding volumes so that traefik can communicate with the underlying host, but the weird thing is that it works flawlessly in one setup but not the other.
Below are my docker version info, docker compose files, the results when inspecting the containers (showing the difference in mounts), and the error message from the container log shown in Docker Desktop.
Why does one proxy container manage to populate mounts while the other doesn't?
Thanks in advance!
docker version
Client:
Cloud integration: 1.0.14
Version: 20.10.6
API version: 1.41
Go version: go1.16.3
Git commit: 370c289
Built: Fri Apr 9 22:49:36 2021
OS/Arch: windows/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.6
API version: 1.41 (minimum version 1.24)
Go version: go1.13.15
Git commit: 8728dd2
Built: Fri Apr 9 22:45:40 2021
OS/Arch: windows/amd64
Experimental: false
docker-compose-v1.yml
version: "3.7"
services:
s4-web:
image: s4admin:484-2
build:
context: .
dockerfile: S4/Admin/Dockerfile
labels:
- "traefik.enable=true"
- "traefik.http.routers.web.rule=PathPrefix(`/`)"
networks:
- sg-net
proxy:
image: traefik:v2.3-windowsservercore-1809
command:
- "--providers.docker"
- "--providers.docker.endpoint=npipe:////./pipe/docker_engine"
- "--providers.docker.exposedbydefault=false"
- "--providers.docker.network=sg-net"
- "--entrypoints.web.address=:80"
- "--api.insecure=true"
ports:
- "8080:80"
- "8088:8080"
volumes:
- type: npipe
source: \\.\pipe\docker_engine
target: \\.\pipe\docker_engine
networks:
- sg-net
networks:
sg-net:
docker-compose-v2.yml
version: "3.7"
services:
signup-web:
image: signup-web:02-06
build:
context: ../..
dockerfile: docker/02-06-platform-integration/signup-web/v6/Dockerfile
environment:
- Dependencies:IReferenceDataLoader=SignUp.Web.ReferenceData.ApiReferenceDataLoader
- ReferenceDataApi:Url=http://reference-data-api/api
- Dependencies:IProspectSaveHandler=SignUp.Web.ProspectSave.AsynchronousProspectSaveHandler
- MessageQueue:Url=nats://${HOST_IP}:4222
labels:
- "traefik.enable=true"
- "traefik.http.routers.web.rule=PathPrefix(`/`)"
networks:
- signup-net
proxy:
image: traefik:v2.3-windowsservercore-1809
command:
- "--providers.docker"
- "--providers.docker.endpoint=npipe:////./pipe/docker_engine"
- "--providers.docker.exposedbydefault=false"
- "--providers.docker.network=signup-net"
- "--entrypoints.web.address=:80"
- "--api.insecure=true"
ports:
- "8080:80"
- "8088:8080"
volumes:
- type: npipe
source: \\.\pipe\docker_engine
target: \\.\pipe\docker_engine
networks:
- signup-net
networks:
signup-net:
Result from docker inspect github_proxy_1 showing no mounts:
[
{
"Id": "507bb53f9f7c772221ef858464877d310c4ab48a100f86e49b5e248de67c5921",
"Created": "2021-05-28T07:49:16.3839919Z",
"Path": "/traefik",
"Args": [
"--providers.docker",
"--providers.docker.endpoint=npipe:////./pipe/docker_engine",
"--providers.docker.exposedbydefault=false",
"--providers.docker.network=sg-net",
"--entrypoints.web.address=:80",
"--api.insecure=true"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 1312,
"ExitCode": 0,
"Error": "",
"StartedAt": "2021-05-28T07:49:22.9474168Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:0011bc7c1cd89741d499d69fe62ed8c50b251d90bb3dd01350d6f945dace6e89",
"ResolvConfPath": "",
"HostnamePath": "",
"HostsPath": "",
"LogPath": "C:\\ProgramData\\Docker\\containers\\507bb53f9f7c772221ef858464877d310c4ab48a100f86e49b5e248de67c5921\\507bb53f9f7c772221ef858464877d310c4ab48a100f86e49b5e248de67c5921-json.log",
"Name": "/github_proxy_1",
"RestartCount": 0,
"Driver": "windowsfilter",
"Platform": "windows",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": [],
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "github_sg-net",
"PortBindings": {
"80/tcp": [
{
"HostIp": "",
"HostPort": "8080"
}
],
"8080/tcp": [
{
"HostIp": "",
"HostPort": "8088"
}
]
},
"RestartPolicy": {
"Name": "",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": [],
"CapAdd": null,
"CapDrop": null,
"CgroupnsMode": "",
"Dns": null,
"DnsOptions": null,
"DnsSearch": null,
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 0,
"ConsoleSize": [
0,
0
],
"Isolation": "hyperv",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": null,
"DeviceCgroupRules": null,
"DeviceRequests": null,
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": null,
"PidsLimit": null,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": null,
"ReadonlyPaths": null
},
"GraphDriver": {
"Data": {
"dir": "C:\\ProgramData\\Docker\\windowsfilter\\507bb53f9f7c772221ef858464877d310c4ab48a100f86e49b5e248de67c5921"
},
"Name": "windowsfilter"
},
"Mounts": [],
"Config": {
"Hostname": "507bb53f9f7c",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": true,
"AttachStderr": true,
"ExposedPorts": {
"80/tcp": {},
"8080/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": null,
"Cmd": [
"--providers.docker",
"--providers.docker.endpoint=npipe:////./pipe/docker_engine", "--providers.docker.exposedbydefault=false",
"--providers.docker.network=sg-net",
"--entrypoints.web.address=:80",
"--api.insecure=true"
],
"Image": "sha256:0011bc7c1cd89741d499d69fe62ed8c50b251d90bb3dd01350d6f945dace6e89",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": [
"/traefik"
],
"OnBuild": null,
"Labels": {
"com.docker.compose.config-hash": "ef67d49c829762590f72bf6caa8e34327f9b86915e9e985c9d2fa43177457894",
"com.docker.compose.container-number": "1",
"com.docker.compose.oneoff": "False",
"com.docker.compose.project": "github",
"com.docker.compose.project.config_files": "C:\\Dev\\Projects\\SurveyGenerator\\github\\docker-compose-s4.yml",
"com.docker.compose.project.working_dir": "C:\\Dev\\Projects\\SurveyGenerator\\github",
"com.docker.compose.service": "proxy",
"com.docker.compose.version": "1.0-alpha",
"org.opencontainers.image.description": "A modern reverse-proxy",
"org.opencontainers.image.documentation": "https://docs.traefik.io",
"org.opencontainers.image.title": "Traefik",
"org.opencontainers.image.url": "https://traefik.io",
"org.opencontainers.image.vendor": "Traefik Labs",
"org.opencontainers.image.version": "v2.3.7"
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "507bb53f9f7c772221ef858464877d310c4ab48a100f86e49b5e248de67c5921",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"80/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "8080"
}
],
"8080/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "8088"
}
]
},
"SandboxKey": "507bb53f9f7c772221ef858464877d310c4ab48a100f86e49b5e248de67c5921",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"github_sg-net": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"proxy",
"github_proxy_1",
"507bb53f9f7c"
],
"NetworkID": "2e5931b8cba8fdd1b2b4e547089c21b85570450437599d13e8af3888263d22e3",
"EndpointID": "87d39c2b7cc69b3090026f8395312704e684d7fb925410895dca1a007473ee41",
"Gateway": "172.27.160.1",
"IPAddress": "172.27.163.11",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "00:15:5d:46:69:3c",
"DriverOpts": null
}
}
}
}
]
Result from docker inspect github_proxy_1 where mounts has values:
[
{
"Id": "a81aae03a323b5efd37f80656dccab0bd102aa903d34803554456f0661c22c99",
"Created": "2021-05-28T08:21:05.6675713Z",
"Path": "/traefik",
"Args": [
"--providers.docker",
"--providers.docker.endpoint=npipe:////./pipe/docker_engine",
"--providers.docker.exposedbydefault=false",
"--providers.docker.network=signup-net",
"--entrypoints.web.address=:80",
"--api.insecure=true"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 1328,
"ExitCode": 0,
"Error": "",
"StartedAt": "2021-05-28T08:21:10.4771044Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:0011bc7c1cd89741d499d69fe62ed8c50b251d90bb3dd01350d6f945dace6e89",
"ResolvConfPath": "",
"HostnamePath": "",
"HostsPath": "",
"LogPath": "C:\\ProgramData\\Docker\\containers\\a81aae03a323b5efd37f80656dccab0bd102aa903d34803554456f0661c22c99\\a81aae03a323b5efd37f80656dccab0bd102aa903d34803554456f0661c22c99-json.log",
"Name": "/03_proxy_1",
"RestartCount": 0,
"Driver": "windowsfilter",
"Platform": "windows",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": [],
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "03_signup-net",
"PortBindings": {
"80/tcp": [
{
"HostIp": "",
"HostPort": "8080"
}
],
"8080/tcp": [
{
"HostIp": "",
"HostPort": "8088"
}
]
},
"RestartPolicy": {
"Name": "",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": [],
"CapAdd": null,
"CapDrop": null,
"CgroupnsMode": "",
"Dns": null,
"DnsOptions": null,
"DnsSearch": null,
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 0,
"ConsoleSize": [
0,
0
],
"Isolation": "hyperv",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": null,
"DeviceCgroupRules": null,
"DeviceRequests": null,
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": null,
"PidsLimit": null,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"Mounts": [
{
"Type": "npipe",
"Source": "\\\\.\\pipe\\docker_engine",
"Target": "\\\\.\\pipe\\docker_engine"
}
],
"MaskedPaths": null,
"ReadonlyPaths": null
},
"GraphDriver": {
"Data": {
"dir": "C:\\ProgramData\\Docker\\windowsfilter\\a81aae03a323b5efd37f80656dccab0bd102aa903d34803554456f0661c22c99"
},
"Name": "windowsfilter"
},
"Mounts": [
{
"Type": "npipe",
"Source": "\\\\.\\pipe\\docker_engine",
"Destination": "\\\\.\\pipe\\docker_engine",
"Mode": "",
"RW": true,
"Propagation": ""
}
],
"Config": {
"Hostname": "a81aae03a323",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"80/tcp": {},
"8080/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": null,
"Cmd": [
"--providers.docker",
"--providers.docker.endpoint=npipe:////./pipe/docker_engine",
"--providers.docker.exposedbydefault=false",
"--providers.docker.network=signup-net",
"--entrypoints.web.address=:80",
"--api.insecure=true"
],
"Image": "traefik:v2.3-windowsservercore-1809",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": [
"/traefik"
],
"OnBuild": null,
"Labels": {
"com.docker.compose.config-hash": "53f350716aad96821fea12154c09bf70e538394230171e0139d28b0ea8b6a2c6",
"com.docker.compose.container-number": "1",
"com.docker.compose.oneoff": "False",
"com.docker.compose.project": "03",
"com.docker.compose.project.config_files": "app\\03\\v7-windows.yml",
"com.docker.compose.project.working_dir": "C:\\Dev\\Projects\\docker4dotnet\\app\\03",
"com.docker.compose.service": "proxy",
"com.docker.compose.version": "1.29.1",
"org.opencontainers.image.description": "A modern reverse-proxy",
"org.opencontainers.image.documentation": "https://docs.traefik.io",
"org.opencontainers.image.title": "Traefik",
"org.opencontainers.image.url": "https://traefik.io",
"org.opencontainers.image.vendor": "Traefik Labs",
"org.opencontainers.image.version": "v2.3.7"
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "a81aae03a323b5efd37f80656dccab0bd102aa903d34803554456f0661c22c99",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"80/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "8080"
}
],
"8080/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "8088"
}
]
},
"SandboxKey": "a81aae03a323b5efd37f80656dccab0bd102aa903d34803554456f0661c22c99",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"03_signup-net": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"a81aae03a323",
"proxy"
],
"NetworkID": "1a464d92f0625acd600391c7b2204d33e54cb94b1bf4a098ca0a48e5f4067edc",
"EndpointID": "fde1dace014a898a4cee3fb624ce1a1ec74f87a565b3cb4696e895037774e57d",
"Gateway": "172.29.0.1",
"IPAddress": "172.29.12.143",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "00:15:5d:2f:e3:79",
"DriverOpts": null
}
}
}
}
]
Logged error message in docker desktop for the github_proxy_1 container without mounts:
time="2021-05-28T09:49:25+02:00" level=error msg="Failed to retrieve information of the docker client and server host: error during connect: This error may indicate that the docker daemon is not running.: Get \"http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/version\": open //./pipe/docker_engine: The system cannot find the file specified." providerName=docker
time="2021-05-28T09:49:25+02:00" level=error msg="Provider connection error error during connect: This error may indicate that the docker daemon is not running.: Get \"http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/version\": open //./pipe/docker_engine: The system cannot find the file specified., retrying in 552.330144ms" providerName=docker
So I found the problem. I was using docker-compose (using the docker-compose binary) for the compose that worked and docker compose for the one that didn't.
The question remains why one works and the other doesn't, what is the difference of running docker-compose vs docker compose? Does it perhaps somehow have to do with permissions?
I am relatively new to Docker and I am attempting to build a single custom image from my Dockerfile using docker-compose.
Dockerfile
FROM continuumio/anaconda3
#create a directory
WORKDIR /home/docker/qts
#copy the dependencies file
COPY ./requirements.txt .
#install necessary packages
RUN pip install --no-cache-dir -r requirements.txt
#Expose ports
EXPOSE 5000
docker-compose.yml
version: "3.8"
services:
pyimg:
build: .
ports:
- 5000:5000
volumes:
- $HOME/Documents/qts:/home/docker/qts
My issue
Running docker-compose build gives me no errors. When I execute docker run -it <image_name> bash and navigate into the directory /home/docker/qts, the directory does not mirror the local directory.
A docker inspect also shows that the volumes are not mounted (and that the ports that I have exposed have also not been mapped to the local ports!) What am I missing here?
Thank you for your input.
[
{
"Id": "cc506e95df8788349090b310bfa6965b56dbb9e218efe4a9024eb2f502a2d2f2",
"Created": "2021-02-27T14:44:14.9474339Z",
"Path": "bash",
"Args": [],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 2712,
"ExitCode": 0,
"Error": "",
"StartedAt": "2021-02-27T14:44:15.2955648Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:332985fd4830584b0356f0bf28500f5b951f7ae1fb0e0b5d774c264e28a900e3",
"ResolvConfPath": "/var/lib/docker/containers/cc506e95df8788349090b310bfa6965b56dbb9e218efe4a9024eb2f502a2d2f2/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/cc506e95df8788349090b310bfa6965b56dbb9e218efe4a9024eb2f502a2d2f2/hostname",
"HostsPath": "/var/lib/docker/containers/cc506e95df8788349090b310bfa6965b56dbb9e218efe4a9024eb2f502a2d2f2/hosts",
"LogPath": "/var/lib/docker/containers/cc506e95df8788349090b310bfa6965b56dbb9e218efe4a9024eb2f502a2d2f2/cc506e95df8788349090b310bfa6965b56dbb9e218efe4a9024eb2f502a2d2f2-json.log",
"Name": "/determined_aryabhata",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"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",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DeviceRequests": null,
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": null,
"Ulimits": null,
"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"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/a802a922e08dd98e4dcebea8253d2457393aa5380ba31698087ebab7c20c7420-init/diff:/var/lib/docker/overlay2/7fd10d3a3749cfbcfb8ba4bffbe4d5ec9b70c0244f18d8bcbc10e50526fa2836/diff:/var/lib/docker/overlay2/a951e71a24b2c5635f34fbac57fe02e902ffa55928854bd63918c3a0eac8bd6a/diff:/var/lib/docker/overlay2/67defaf9804e20dbe3bb9b06a68301b527cebf5ad15103d129b564b4678f65eb/diff:/var/lib/docker/overlay2/7e88aebe633878bdd3fe36eb842259d1e898f64fd6937a47ac7b32cb77958fe0/diff:/var/lib/docker/overlay2/61c831913d4448f0efa8b78852181b45c993aa6d5d6b1d7b01e85f936121ab4d/diff:/var/lib/docker/overlay2/dc34279b6529ec9d0123de5a46520de90775fe9ad0d87f8e8a572085df7bf3d3/diff",
"MergedDir": "/var/lib/docker/overlay2/a802a922e08dd98e4dcebea8253d2457393aa5380ba31698087ebab7c20c7420/merged",
"UpperDir": "/var/lib/docker/overlay2/a802a922e08dd98e4dcebea8253d2457393aa5380ba31698087ebab7c20c7420/diff",
"WorkDir": "/var/lib/docker/overlay2/a802a922e08dd98e4dcebea8253d2457393aa5380ba31698087ebab7c20c7420/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "cc506e95df87",
"Domainname": "",
"User": "",
"AttachStdin": true,
"AttachStdout": true,
"AttachStderr": true,
"ExposedPorts": {
"5000/tcp": {}
},
"Tty": true,
"OpenStdin": true,
"StdinOnce": true,
"Env": [
"PATH=/opt/conda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
You can not see with docker run you can check like below;
version: "3.8"
services:
pyimg:
build: .
ports:
- 5000:5000
volumes:
- $HOME/Documents/qts:/home/docker/qts
command:
- /bin/bash
- -c
- sleep 60
With docker ps find your container id than;
docker exec -it ID /bin/bash
And
ls
I am trying to run chrome container.
This works for me:
[practice]$ docker run -d -p 4444:4444 -v /dev/shm:/dev/shm selenium/standalone-chrome
b7d63881869721fe66a4f00de4be7a3bfb8e922410776a7c35f827bfd08f9455
[practice]$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b7d638818697 selenium/standalone-chrome "/opt/bin/entry_poin…" 22 seconds ago Up 22 seconds 0.0.0.0:4444->4444/tcp lucid_sammet
But my requirement is to have an additional package inside my container, so i created a DockerFile
FROM selenium/standalone-chrome
FROM node:latest
RUN npm install --save #ffmpeg-installer/ffmpeg
And created a build using:
[practice]$ docker build -t mychrome:1.0 .
Sending build context to Docker daemon 15.34MB
Step 1/3 : FROM selenium/standalone-chrome
---> c84475653f71
Step 2/3 : FROM node:latest
---> a511eb5c14ec
Step 3/3 : RUN npm install --save #ffmpeg-installer/ffmpeg
---> Using cache
---> 2d04ced6065c
Successfully built 2d04ced6065c
Successfully tagged mychrome:1.0
But when i create container, it gets killed by itself.
[practice]$ docker run -d -p 4444:4444 -v /dev/shm:/dev/shm mychrome:1.0
1e6416ff6d232cc7fb1990ac5ae425af72d6456ec2a94d6b575431edb9e04211
[practice]$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Here are docker inspect:
[practice]$ docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1e6416ff6d23 mychrome:1.0 "docker-entrypoint.s…" 2 minutes ago Exited (0) 2 minutes ago compassionate_panini
b2dcd66a3f97 mychrome:1.0 "docker-entrypoint.s…" 2 minutes ago Created elegant_mcc
[practice]$ docker inspect 1e6416ff6d23
[
{
"Id": "1e6416ff6d232cc7fb1990ac5ae425af72d6456ec2a94d6b575431edb9e04211",
"Created": "2020-05-09T06:51:21.8510204Z",
"Path": "docker-entrypoint.sh",
"Args": [
"node"
],
"State": {
"Status": "exited",
"Running": false,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 0,
"ExitCode": 0,
"Error": "",
"StartedAt": "2020-05-09T06:51:22.1525569Z",
"FinishedAt": "2020-05-09T06:51:22.331137Z"
},
"Image": "sha256:2d04ced6065c32a7f1e2d3d28988302b7e762533f7964b8bcbe344f05ba65fdc",
"ResolvConfPath": "/var/lib/docker/containers/1e6416ff6d232cc7fb1990ac5ae425af72d6456ec2a94d6b575431edb9e04211/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/1e6416ff6d232cc7fb1990ac5ae425af72d6456ec2a94d6b575431edb9e04211/hostname",
"HostsPath": "/var/lib/docker/containers/1e6416ff6d232cc7fb1990ac5ae425af72d6456ec2a94d6b575431edb9e04211/hosts",
"LogPath": "/var/lib/docker/containers/1e6416ff6d232cc7fb1990ac5ae425af72d6456ec2a94d6b575431edb9e04211/1e6416ff6d232cc7fb1990ac5ae425af72d6456ec2a94d6b575431edb9e04211-json.log",
"Name": "/compassionate_panini",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": [
"/dev/shm:/dev/shm"
],
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {
"4444/tcp": [
{
"HostIp": "",
"HostPort": "4444"
}
]
},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Capabilities": null,
"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",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DeviceRequests": null,
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": null,
"Ulimits": null,
"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"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/55f20b215a1ff36c8ebb1dff18cac13e9b0a8fb30d5e81a7bd98c8d259a53cde-init/diff:/var/lib/docker/overlay2/d9ffce8fb048fc9b3f06d8bf9722848e1c634fa62c6cddf3b81c8fd69f168d15/diff:/var/lib/docker/overlay2/ac6f63198e071b53404e7f46a18e442fbb3940bd1ab33689b14c3cefd0cec63f/diff:/var/lib/docker/overlay2/27e169d3a5ecd1eb5a1a169fd295b8bcb01c03bb0de80609bf1f8b807a922ab0/diff:/var/lib/docker/overlay2/1bc8d050ec3936a42bfc5274d3857b0b507245798226de02db185a4bed2ee505/diff:/var/lib/docker/overlay2/e51f7d0d89f2480c94a247f4fece58ba82ecf0139b3d066a7154f74ea196fb67/diff:/var/lib/docker/overlay2/6a241e18bf0fed51affe0f856b9a685d81db7ecd3b5e73754ce94d3a77e66173/diff:/var/lib/docker/overlay2/8c2950f8c31da7a939c93f9fe187c52eea8317a4b64ee2c3b75b09e2db924ce5/diff:/var/lib/docker/overlay2/1fce7515c1871f43e30f3761ef340c8a85fc7de0c3902299db206a2ba0461bd3/diff:/var/lib/docker/overlay2/84d7667120601df8ff0c8187d350fe3700611a7eb9294dde6d6ce8343150551d/diff:/var/lib/docker/overlay2/26c37b434064f095df1114f55e37487094c1efcd8c4bb7b40507da171553210c/diff",
"MergedDir": "/var/lib/docker/overlay2/55f20b215a1ff36c8ebb1dff18cac13e9b0a8fb30d5e81a7bd98c8d259a53cde/merged",
"UpperDir": "/var/lib/docker/overlay2/55f20b215a1ff36c8ebb1dff18cac13e9b0a8fb30d5e81a7bd98c8d259a53cde/diff",
"WorkDir": "/var/lib/docker/overlay2/55f20b215a1ff36c8ebb1dff18cac13e9b0a8fb30d5e81a7bd98c8d259a53cde/work"
},
"Name": "overlay2"
},
"Mounts": [
{
"Type": "bind",
"Source": "/dev/shm",
"Destination": "/dev/shm",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],
"Config": {
"Hostname": "1e6416ff6d23",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"4444/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"NODE_VERSION=14.1.0",
"YARN_VERSION=1.22.4"
],
"Cmd": [
"node"
],
"Image": "mychrome:1.0",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": [
"docker-entrypoint.sh"
],
"OnBuild": null,
"Labels": {}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "c14a931bf5ad40900b83e8f1ee770d270765af1ff181ff610ed2b564d12e3f13",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/c14a931bf5ad",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "51bc10f592d1c05978822f1f5c8a108dffa0581fd6c639e73984bf0760831564",
"EndpointID": "",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "",
"DriverOpts": null
}
}
}
}
]
Please let me what is wrong here.
got it working by using this dockerfile:
FROM node:latest AS node_base
RUN echo "NODE Version:" && node --version
RUN echo "NPM Version:" && npm --version
RUN npm install --save #ffmpeg-installer/ffmpeg
RUN echo "NPM Modules:" && npm ls
FROM selenium/standalone-chrome
USER root
COPY --from=node_base . .
RUN echo "NPM Modules:" && npm ls
RUN echo "file ends..."
Upon going inside the container, For some reason it reads the code from this location, I don't know how and from where is the code being loaded here:
/home/mean
But the needed ( real code ) contents are being uploaded here:
/opt/ltg/
Here's my docker-compose file contents, I think the issue is with the VOLUMES parameter.
When i try to go inside the container, and look for the html views, turns out it is linked with another folder that i used before.
I'm using https://github.com/meanjs/mean meanjs to build my project so I'm using their docker files, so their way of using the docker.
version: '2'
services:
web:
restart: always
build: .
container_name: ltg
ports:
- "3000:3000"
- "5858:5858"
- "8080:8080"
- "35729:35729"
environment:
- NODE_ENV=development
- DB_1_PORT_27017_TCP_ADDR=db
depends_on:
- db
volumes_from:
- web-data
web-data:
build: .
entrypoint: /bin/true
volumes:
- ./:/opt/ltg
- /opt/ltg/node_modules
- /opt/ltg/public
- /opt/ltg/uploads
db:
image: mongo:3.2
restart: always
ports:
- "27017:27017"
volumes_from:
- db-data
db-data:
image: mongo:3.2
volumes:
- /data/db
- /var/lib/mongodb
- /var/log/mongodb
entrypoint: /bin/true
Dockerfile. ( I think the issue is here ) but even when i change the /home/mean to /opt/ltg it doesn't seem to work.
FROM node:0.12
# Install gem sass for grunt-contrib-sass
RUN apt-get update -qq && apt-get install -y build-essential
RUN apt-get install -y ruby
RUN gem install sass
WORKDIR /opt/ltg
# Install Mean.JS Prerequisites
RUN npm install -g grunt-cli
RUN npm install -g bower
# Install Mean.JS packages
ADD package.json /opt/ltg/package.json
RUN npm install
# Manually trigger bower. Why doesnt this work via npm install?
ADD .bowerrc /opt/ltg/.bowerrc
ADD bower.json /opt/ltg/bower.json
RUN bower install --config.interactive=false --allow-root
# Make everything available for start
ADD . /opt/ltg
# Set development environment as default
ENV NODE_ENV development
# Port 3000 for server
# Port 35729 for livereload
EXPOSE 3000 35729
CMD ["grunt"]
When i go inside the docker machine I can see that it does have the code inside but I dont know why is it picking it from another place.
Docker inspect
± docker inspect e8a6e44e7a78
[
{
"Id": "e8a6e44e7a78825d5d4ebd9e165d24151e391e66478a5214f0ecd7badcf71d51",
"Created": "2016-11-11T21:51:59.315251772Z",
"Path": "grunt",
"Args": [],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 6521,
"ExitCode": 0,
"Error": "",
"StartedAt": "2016-11-11T21:52:00.23437815Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:8b93f26cc274bf69cd9e2c24161ef8b1a09acc958fb94027838897b0bf860d4e",
"ResolvConfPath": "/var/lib/docker/containers/e8a6e44e7a78825d5d4ebd9e165d24151e391e66478a5214f0ecd7badcf71d51/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/e8a6e44e7a78825d5d4ebd9e165d24151e391e66478a5214f0ecd7badcf71d51/hostname",
"HostsPath": "/var/lib/docker/containers/e8a6e44e7a78825d5d4ebd9e165d24151e391e66478a5214f0ecd7badcf71d51/hosts",
"LogPath": "/var/lib/docker/containers/e8a6e44e7a78825d5d4ebd9e165d24151e391e66478a5214f0ecd7badcf71d51/e8a6e44e7a78825d5d4ebd9e165d24151e391e66478a5214f0ecd7badcf71d51-json.log",
"Name": "/ltg",
"RestartCount": 0,
"Driver": "overlay2",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": [],
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "ltg_default",
"PortBindings": {
"3000/tcp": [
{
"HostIp": "",
"HostPort": "3000"
}
],
"35729/tcp": [
{
"HostIp": "",
"HostPort": "35729"
}
],
"5858/tcp": [
{
"HostIp": "",
"HostPort": "5858"
}
],
"8080/tcp": [
{
"HostIp": "",
"HostPort": "8080"
}
]
},
"RestartPolicy": {
"Name": "always",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": [],
"CapAdd": null,
"CapDrop": null,
"Dns": null,
"DnsOptions": null,
"DnsSearch": null,
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": null,
"DiskQuota": 0,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": -1,
"OomKillDisable": false,
"PidsLimit": 0,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0
},
"GraphDriver": {
"Name": "overlay2",
"Data": {
"LowerDir": "/var/lib/docker/overlay2/aedc2da47ce0785a68ea3786cf35eded82b6e5eb57e7083353d2c68ebfa1d15e-init/diff:/var/lib/docker/overlay2/ba7c11c0aac2c7c97c6f0d2876ed600b3724c0cabaa40d58f579db4573b4e8ed/diff:/var/lib/docker/overlay2/807a7a90f77a22724db8e54a57ad91b1ef1f2b06e88ad42524042f46c9da39d7/diff:/var/lib/docker/overlay2/14cbc06a270e4fddd6287d8f90cb2e885b1387be4dc0b79678f866b59e12063c/diff:/var/lib/docker/overlay2/369cc5f5a0ba13fe12e2d42d35f78f1bfcfdd80c0a0d64f0a22e9a6a036149aa/diff:/var/lib/docker/overlay2/854bf8973559090707e5d89c820ae70539392f9970b1646fb8178ff401ae3c5b/diff:/var/lib/docker/overlay2/d6db404071f5f6741dc2555bb87142f0fbfb511a7c70f03085ddcae108bbf5ae/diff:/var/lib/docker/overlay2/869b67fd3eb7e0f4856433eddd0dd1604170bf8d70c97070a4c1866c46a82024/diff:/var/lib/docker/overlay2/2fa6daceeb2d0b83fcb08a8b46d8894f182c8e2bb206e87d5af0e7fc73452c29/diff:/var/lib/docker/overlay2/b61d40c66620b7088c0ba4d37e776eef9a40ece901cf2e1ead26c8cbde3ebfe5/diff:/var/lib/docker/overlay2/c2470f33522483b8c7f2651e24ebee088f27fcdac2b8b93e9183e5d022ebc883/diff:/var/lib/docker/overlay2/a48f7cee20a989218f7eb20a8d6bc0b31a3c3e4e968a0a5271a13297a2b37b89/diff:/var/lib/docker/overlay2/e69b54cfe8a5a5c5cacf5e77603bd6e24695dba569c6bf5b0c9788f4b008c22c/diff:/var/lib/docker/overlay2/2dd3ff884efc421fed1e548a4b0c6c633dd59b62c077811718ed5b7bf0fde7fd/diff:/var/lib/docker/overlay2/b5c1cc249ce2798dbfff752cd2f4878bc7777951cd11013ceecb44d0eb933aff/diff:/var/lib/docker/overlay2/e9006ecc5d8f18345f402c96e9149b2b0dd6689d1d476b896049237ea41de404/diff:/var/lib/docker/overlay2/2debe0ee8462910da0e18bbd9ac6c1c902b157f7b15b23f866add9163d008aa3/diff:/var/lib/docker/overlay2/d0bc087a8ea87721eb7feb31dd7999e6e9755e991b88f4e728fc93669ee8590e/diff:/var/lib/docker/overlay2/76deca402cfba36204612590cb0de02a5ff8fab6d6053263af0a81e6da79fb78/diff:/var/lib/docker/overlay2/737638f3bceb8c85288c3477da936e3b523dbabd787e72989e639df24195329b/diff",
"MergedDir": "/var/lib/docker/overlay2/aedc2da47ce0785a68ea3786cf35eded82b6e5eb57e7083353d2c68ebfa1d15e/merged",
"UpperDir": "/var/lib/docker/overlay2/aedc2da47ce0785a68ea3786cf35eded82b6e5eb57e7083353d2c68ebfa1d15e/diff",
"WorkDir": "/var/lib/docker/overlay2/aedc2da47ce0785a68ea3786cf35eded82b6e5eb57e7083353d2c68ebfa1d15e/work"
}
},
"Mounts": [],
"Config": {
"Hostname": "e8a6e44e7a78",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"3000/tcp": {},
"35729/tcp": {},
"5858/tcp": {},
"8080/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"NODE_ENV=development",
"DB_1_PORT_27017_TCP_ADDR=db",
"no_proxy=*.local, 169.254/16",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"NODE_VERSION=0.12.17"
],
"Cmd": [
"grunt"
],
"Image": "ltg_web",
"Volumes": null,
"WorkingDir": "/home/mean",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"com.docker.compose.config-hash": "7a3cb3d6a460fc5a975aafe44279ec835e5bb92141ae537ac0fd044c94243abe",
"com.docker.compose.container-number": "1",
"com.docker.compose.oneoff": "False",
"com.docker.compose.project": "ltg",
"com.docker.compose.service": "web",
"com.docker.compose.version": "1.9.0-rc2"
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "a1b78ae1a7e589977a6f23e1fe1274bb494324b7ce7b9f99d16bb7e78678f721",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"3000/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "3000"
}
],
"35729/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "35729"
}
],
"5858/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "5858"
}
],
"8080/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "8080"
}
]
},
"SandboxKey": "/var/run/docker/netns/a1b78ae1a7e5",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"ltg_default": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"web",
"e8a6e44e7a78"
],
"NetworkID": "cdde7613dceaf26fac855d124172f3b0606ab685585a69974e87c4f4ed4fed6c",
"EndpointID": "b4618fb75407538391035f610281374407c9b9a513028ccf981a390d689dbe93",
"Gateway": "172.19.0.1",
"IPAddress": "172.19.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:13:00:03"
}
}
}
}
]
I dont undersatnd from where is this /home/mean coming inside the variable
"WorkingDir": "/home/mean",
I think we need a little more information to properly answer the question. So I will assume some things.
The opt/ltg directory points to the directory where your docker-compose.yml is located, not the directory where you run docker-compose. Usually is the same directory. Try to make a modification I your docker-compose.yml like add a comment. Go to the container with docker exec and check the content of your docker-compose.yml, the added comment should be there.
I assume that your html files go to /opt/ltg/public as you declared it as a volume also. Docker will create another directory in your host for this different from your current directory. Use a docker inspect to see where are they. If you run a docker-compose down -v you should get rid of those files.
Don't overlap volumes unless you really need to. I recommend use this docker-compose.yml instead:
docker-compose.yml
version: '2'
services:
web:
restart: always
build: .
container_name: ltg
ports:
- "3000:3000"
- "5858:5858"
- "8080:8080"
- "35729:35729"
environment:
- NODE_ENV=development
- DB_1_PORT_27017_TCP_ADDR=db
depends_on:
- db
volumes_from:
- web-data
web-data:
build: .
entrypoint: /bin/true
volumes:
- ./:/opt/ltg
db:
image: mongo:3.2
restart: always
ports:
- "27017:27017"
volumes_from:
- db-data
db-data:
image: mongo:3.2
volumes:
- /data/db
- /var/lib/mongodb
- /var/log/mongodb
entrypoint: /bin/true
Regards