我试图在docker中运行我的restful api,但是我的golang可执行文件有问题,它总是找不到。这是我的 Dockerfile# Start from golang base imageFROM golang:1.15.2#Set ENVENV DB_HOST=fullstack-mysql \ DB_DRIVER=mysql \ DB_USER=root \ DB_PASSWORD=root \ DB_NAME=link_aja \ DB_PORT=3306 \ APP_NAME=golang-linkaja \ CGO_ENABLED=0 # Copy the source from the current directory to the working Directory inside the container COPY . /usr/src/${APP_NAME}# Move to working directoryWORKDIR /usr/src/${APP_NAME}#install depedenciesRUN go mod download# Build the applicationRUN go build -o ${APP_NAME}# Expose port 3000 to the outside worldEXPOSE 3000#Command to run the executableCMD ${APP_NAME}这是我的 docker-compose.ymlversion: '3'services: app: container_name: golang-linkaja build: . ports: - 3000:3000 restart: on-failure volumes: - api:/usr/src/${APP_NAME} depends_on: - fullstack-mysql networks: - fullstack fullstack-mysql: image: mysql:5.7 container_name: full_db_mysql ports: - 3306:3306 environment: - MYSQL_ROOT_HOST=${DB_HOST} - MYSQL_USER=${DB_USER} - MYSQL_PASSWORD=${DB_PASSWORD} - MYSQL_DATABASE=${DB_NAME} - MYSQL_ROOT_PASSWORD=${DB_PASSWORD} volumes: - database_mysql:/var/lib/mysql networks: - fullstack phpmyadmin: image: phpmyadmin/phpmyadmin container_name: phpmyadmin_container depends_on: - fullstack-mysql environment: - PMA_HOST=fullstack-mysql #DB_HOST env must be the same with this - PMA_USER=${DB_USER} - PMA_PORT=${DB_PORT} - PMA_PASSWORD=${DB_PASSWORD} ports: - 9090:80 restart: always networks: - fullstackvolumes: api: database_mysql: # Networks to be created to facilitate communication between containersnetworks: fullstack: driver: bridge
2 回答
子衿沉夜
TA贡献1828条经验 获得超3个赞
您需要从撰写中删除该卷。您已经在 .卷(在 compose 中定义)正在覆盖所有数据,因此找不到构建的二进制文件。 - api:/usr/src/${APP_NAME}
Dockerfile
只需删除卷,然后尝试重建并再次启动容器....并将您的 cmd 更改为CMD [ "./${APP_NAME}" ]
侃侃尔雅
TA贡献1801条经验 获得超16个赞
在 Dockerfile 中,您尝试在不使用前缀的情况下运行可执行文件,因此操作系统在系统文件夹上搜索可执行文件,但找不到它。添加 CMD 的开头或使用可执行文件的绝对路径。./
./
#Command to run the executable CMD ./${APP_NAME}
或
#Command to run the executable CMD /usr/src/${APP_NAME}
- 2 回答
- 0 关注
- 207 浏览
添加回答
举报
0/150
提交
取消