嗨,我是docker和docker-compose的新手。
这是我的docker-compose
version: "2.1"
services:
licenseserver:
build:
context: ./licenseserver
dockerfile: .dockerfile
ports:
- "20000:20000"
mac_address: C8-D9-D2-A5-8F-DE
hostname: idol
dockerfile内容
FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install unzip
RUN mkdir /opt/MicroFocus
WORKDIR /opt/MicroFocus
ADD LicenseServer.zip /opt/MicroFocus
RUN chmod 777 LicenseServer.zip
RUN unzip LicenseServer.zip
RUN rm -f LicenseServer.zip
WORKDIR /opt/MicroFocus/LicenseServer_12.5.0_LINUX_X86_64
ADD idol.dat /opt/MicroFocus/LicenseServer_12.5.0_LINUX_X86_64
RUN ls -lart
RUN pwd
RUN ./start-licenseserver.sh
docker-compose构建工作正常,但是当我运行docker-compose时,得到以下信息。如何确保容器继续运行。
root@development-vm:/home/vinay/docker/AT# docker-compose up
Starting at_licenseserver_1 ... done
Attaching to at_licenseserver_1
at_licenseserver_1 exited with code 0
root@development-vm:/home/vinay/docker/AT# docker-compose exec licenseserver bash
ERROR: No container found for licenseserver_1
start-licenseserver.sh的内容如下
#!/bin/sh
LD_LIBRARY_PATH=./:../bin:./ffmpeg:./filters:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
clear
echo "--------------------------------------------------------------------"
echo "Micro Focus License Server"
echo "(c) 1999-2018 Micro Focus"
echo "--------------------------------------------------------------------"
echo "This script will start License Server"
echo "(licenseserver.exe)"
echo ""
echo "Hit return to continue"
echo "Hit Ctrl-C to end this script now!"
echo "--------------------------------------------------------------------"
read DUMMY
echo "Starting License Server..."
chmod u+x licenseserver.exe
nohup $PWD/licenseserver.exe > licenseserver.out 2> licenseserver.err &
serverpid=$!
echo "Started License Server with PID $serverpid"
exit
答案 0 :(得分:1)
您应该将Dockerfile更改为仅在构建Docker映像时使用CMD
命令,而不使用RUN
,RUN
命令。 docker希望您的容器运行entrypoint或command,并且它必须是后台进程,例如Web服务器。
检查此article关于RUN
,CMD
和entrypoint
的区别
将您的Dockerfile更改为此,然后尝试再次运行它:
FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install unzip
RUN mkdir /opt/MicroFocus
WORKDIR /opt/MicroFocus
ADD LicenseServer.zip /opt/MicroFocus
RUN chmod 777 LicenseServer.zip
RUN unzip LicenseServer.zip
RUN rm -f LicenseServer.zip
WORKDIR /opt/MicroFocus/LicenseServer_12.5.0_LINUX_X86_64
ADD idol.dat /opt/MicroFocus/LicenseServer_12.5.0_LINUX_X86_64
RUN ls -lart
RUN pwd
CMD ["start-licenseserver.sh"]