以下是roleA.yml
- name: Create container
docker_container:
name: my_container
image: my_image:v0.2
ports:
- "0.0.0.0:8765:8765/tcp"
- "0.0.0.0:80:80/tcp"
state: started
command: service apache2 restart
以下是main.yml
- name: Launching container.
hosts: localhost
environment:
PYTHONPATH: "/usr/local/lib/python2.7/site-packages"
roles:
- roleA
以下是我用来启动容器的命令。
ansible-playbook main.yml
但每当我执行此命令时,容器就会启动并在几秒钟内退出。我甚至尝试了Fail to start container using docker_container module after docker for mac update中建议的不同解决方案。我不确定我做错了什么。
请帮忙。提前致谢。 如果您需要更多信息,请告诉我。
答案 0 :(得分:1)
您必须在前台启动Apache服务。
<强> Run apache in the foreground 强>
$ apachectl -d . -f httpd.conf -e info -DFOREGROUND
-d . sets the ServerRoot to the current directory. All relative paths within the configuration file will resolve to this root.
-f httpd.conf sets the configuration file to use. Note that this is relative to the ServerRoot, not the current working directory. In this case, the ServerRoot is the current working directory, so httpd.conf needs to exist in the current working directory.
-e info sets the logging level for startup. This is different than the log level set in the configuration file.
-DFOREGROUND defines the special apache directive that will cause the parent process to run in the foreground and not detach from the shell.