Задать вопрос
@Boris007

Почему после запуска контейнера к нему нельзя подключиться в браузере?

Без докера проект запускается командой npm run dev
Но в докере после запуска пишет, что приложение запущено
Почему при попытке зайти на http://localhost:5173/ выдает
657303439ee24614203983.png

dockerfile
FROM node:20
WORKDIR /app
COPY package*.json .
RUN npm install
COPY . .
CMD ["npm", "run", "dev"]
EXPOSE 5173


Настройки запуска образа
657302748749e785402334.png

Логи после запуска
2023-12-08 14:48:15 
2023-12-08 14:48:15 > react@0.0.0 dev
2023-12-08 14:48:15 > vite
2023-12-08 14:48:15 
2023-12-08 14:48:16 
2023-12-08 14:48:16   VITE v4.4.9  ready in 416 ms
2023-12-08 14:48:16 
2023-12-08 14:48:16   ➜  Local:   http://localhost:5173/
2023-12-08 14:48:16   ➜  Network: use --host to expose


Inspect в докере
{
	"Id": "f0b3b9cfac73342514511d920e1a36791e5bc36df23c2529c513542e2834e394",
	"Created": "2023-12-08T11:48:14.819864275Z",
	"Path": "docker-entrypoint.sh",
	"Args": [
		"npm",
		"run",
		"dev"
	],
	"State": {
		"Status": "running",
		"Running": true,
		"Paused": false,
		"Restarting": false,
		"OOMKilled": false,
		"Dead": false,
		"Pid": 799,
		"ExitCode": 0,
		"Error": "",
		"StartedAt": "2023-12-08T11:48:15.216801589Z",
		"FinishedAt": "0001-01-01T00:00:00Z"
	},
	"Image": "sha256:60591be30ae16cc46843d7da4a2c37388a806060cb4d3059f727a302b6b139c9",
	"ResolvConfPath": "/var/lib/docker/containers/f0b3b9cfac73342514511d920e1a36791e5bc36df23c2529c513542e2834e394/resolv.conf",
	"HostnamePath": "/var/lib/docker/containers/f0b3b9cfac73342514511d920e1a36791e5bc36df23c2529c513542e2834e394/hostname",
	"HostsPath": "/var/lib/docker/containers/f0b3b9cfac73342514511d920e1a36791e5bc36df23c2529c513542e2834e394/hosts",
	"LogPath": "/var/lib/docker/containers/f0b3b9cfac73342514511d920e1a36791e5bc36df23c2529c513542e2834e394/f0b3b9cfac73342514511d920e1a36791e5bc36df23c2529c513542e2834e394-json.log",
	"Name": "/stupefied_heisenberg",
	"RestartCount": 0,
	"Driver": "overlay2",
	"Platform": "linux",
	"MountLabel": "",
	"ProcessLabel": "",
	"AppArmorProfile": "",
	"ExecIDs": null,
	"HostConfig": {
		"Binds": [],
		"ContainerIDFile": "",
		"LogConfig": {
			"Type": "json-file",
			"Config": {}
		},
		"NetworkMode": "default",
		"PortBindings": {},
		"RestartPolicy": {
			"Name": "",
			"MaximumRetryCount": 0
		},
		"AutoRemove": false,
		"VolumeDriver": "",
		"VolumesFrom": null,
		"ConsoleSize": [
			0,
			0
		],
		"CapAdd": null,
		"CapDrop": null,
		"CgroupnsMode": "host",
		"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",
		"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,
		"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/15c17c5fef0c824bbb886f2c2b31db9faca10f03d4bd2fb5c2e7185a5fba325b-init/diff:/var/lib/docker/overlay2/yqwnjvx0rbr643ywhh0j5xfvx/diff:/var/lib/docker/overlay2/xtwtjegx67ecuail8khuixsv6/diff:/var/lib/docker/overlay2/x523wxolc8fdgmze3i5mod1wv/diff:/var/lib/docker/overlay2/jj044vjs9w091p444sp9z3264/diff:/var/lib/docker/overlay2/7ec4d3d7b85b8a9dc91181a3894e436f3d9aeb1384c6c2b785687fda21b66920/diff:/var/lib/docker/overlay2/673c14393ad170c354f52395d7efee596e7eae85bc594d5c33ccc4b8addd481d/diff:/var/lib/docker/overlay2/64773042ac028d10580f5b4cba8162a9e21289ab1872cb2787f02c4a84d02989/diff:/var/lib/docker/overlay2/244e9146e86802530ca996a2e05062b66284274e3f5bfbaba165ad704845bbe7/diff:/var/lib/docker/overlay2/44f7d2a13ee86fe23bfa8c275e96c63a9eddf5f0777761e00f4bc496b7faa46e/diff:/var/lib/docker/overlay2/dc1d6b25694124bd05c66acf21f2614094c579c8daa2fdcd8cc47e7b1da1fe5b/diff:/var/lib/docker/overlay2/00a1888a294514c536d0b65ec029b5912818eae7d3a7f01dfaf603f1dd868f16/diff:/var/lib/docker/overlay2/aa39d4ada903fa6e9cd38a976645064ad0ae66be66db33cd5299992092044e46/diff",
			"MergedDir": "/var/lib/docker/overlay2/15c17c5fef0c824bbb886f2c2b31db9faca10f03d4bd2fb5c2e7185a5fba325b/merged",
			"UpperDir": "/var/lib/docker/overlay2/15c17c5fef0c824bbb886f2c2b31db9faca10f03d4bd2fb5c2e7185a5fba325b/diff",
			"WorkDir": "/var/lib/docker/overlay2/15c17c5fef0c824bbb886f2c2b31db9faca10f03d4bd2fb5c2e7185a5fba325b/work"
		},
		"Name": "overlay2"
	},
	"Mounts": [],
	"Config": {
		"Hostname": "f0b3b9cfac73",
		"Domainname": "",
		"User": "",
		"AttachStdin": false,
		"AttachStdout": false,
		"AttachStderr": false,
		"ExposedPorts": {
			"5173/tcp": {}
		},
		"Tty": false,
		"OpenStdin": false,
		"StdinOnce": false,
		"Env": [
			"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
			"NODE_VERSION=20.10.0",
			"YARN_VERSION=1.22.19"
		],
		"Cmd": [
			"npm",
			"run",
			"dev"
		],
		"Image": "test07122023:latest",
		"Volumes": null,
		"WorkingDir": "/app",
		"Entrypoint": [
			"docker-entrypoint.sh"
		],
		"OnBuild": null,
		"Labels": {}
	},
	"NetworkSettings": {
		"Bridge": "",
		"SandboxID": "ff1760b9583f0ea6aff78746d4e6ee2668d0b6b589c3697c78cbcf07ca93ff50",
		"HairpinMode": false,
		"LinkLocalIPv6Address": "",
		"LinkLocalIPv6PrefixLen": 0,
		"Ports": {
			"5173/tcp": null
		},
		"SandboxKey": "/var/run/docker/netns/ff1760b9583f",
		"SecondaryIPAddresses": null,
		"SecondaryIPv6Addresses": null,
		"EndpointID": "bf6e97d5cc5496264d5b65cb5872a6f59964055ef2dcb06b57ee241f4d4aa48b",
		"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": "b4bc5f7b0651295cee202d6fdb765ad41cddbb5d8de84c26b46974dc25e11a7e",
				"EndpointID": "bf6e97d5cc5496264d5b65cb5872a6f59964055ef2dcb06b57ee241f4d4aa48b",
				"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
			}
		}
	}
}


657303fad4839819267975.png
  • Вопрос задан
  • 403 просмотра
Подписаться 1 Средний 5 комментариев
Решения вопроса 1
@D3lphi
Ну так вы порт из контейнера не пробросили.

Вот здесь в "Host port" 5173 укажите и все будет доступно.
Здесь

657302748749e785402334.png
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
@Drno
Потому что докер это как бы отдельная "ОС", и там свой личный локалхост...
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы