使用docker映像通过dockerfile构建其他docker映像 [英] Use a docker image to build a different docker image using a dockerfile
问题描述
我正在尝试使用docker文件构建flask应用程序的docker映像。 flask应用程序使用特定sql版本datajoint / mysql的docker映像(使用docker-compose)。但是我收到以下错误:
/ bin / sh:1:泊坞窗:找不到
命令'/ bin / sh -c docker run -v /var/run/docker.sock:/var/run/docker.sock ...'返回了非零代码:127
我也将docker和docker-compose复制到了我的app /目录中。请您帮我如何安装Docker映像并从Docker文件调用Docker。我经历了以下
非常感谢您的帮助。
@DavidMaze是正确的,因为 docker-compose
最有可能在主机上并排运行多个Docker容器的最干净的方法。一旦习惯了它的声明,它实际上便是记录本地/原型设置的好方法。
看看此处为提供的参考 docker-compose
datajoint / mysql
图片。特别是在您共享的设置中,如果您的 Dockerfile
位于 datajoint-python
所在的目录中,与 docker-compose.yml
相同的目录,您可以像这样实现它:
版本: 2.4
服务:
db:
图片:datajoint / mysql:5.7
环境:
-MYSQL_ROOT_PASSWORD = simple
网络:
-主
#端口:
#- 3306:3306
#卷:
#-./data:/var/lib/mysql
dj:
build:。
取决于:
db:
条件:service_healthy
环境:
-DJ_HOST = db
-DJ_USER = root
-DJ_PASS = simple
网络:
-主要
网络:
主要:
注意:我故意使用 2.X
docker-compose
版本的唯一原因是 3.X
版本适用于不需要此类检查的Docker Swarm部署。
I am trying to build a docker image of a flask app using a docker file. The flask app uses a docker image of specific sql version datajoint/mysql (using docker-compose). But I get the following error:
/bin/sh: 1: docker: not found
The command '/bin/sh -c docker run -v /var/run/docker.sock:/var/run/docker.sock ...' returned a non-zero code: 127
I have also copied the docker and docker-compose to my app/ directory. Please can you help me how to install docker image and call docker from a docker file. I have gone through the following link but it doesn't address my problem directly
Dockerfile
# this is an official Python runtime, used as the parent image
FROM python:3.6.5-slim
# set the working directory in the container to /app
WORKDIR /app
# add the current directory to the container as /app
ADD . /app
# execute everyone's favorite pip command, pip install -r
RUN docker run -v /var/run/docker.sock:/var/run/docker.sock ...
RUN ./docker-compose up -d
RUN ./docker run -p 3306:3306 -e MYSQL_ROOT_PASSWORD=simple datajoint/mysql
# add the current directory to the container as /app
ADD . /app
# execute everyone's favorite pip command, pip install -r
RUN pip install --trusted-host pypi.python.org -r requirements.txt
ADD /datajoint-python /datajoint-python
RUN pip install -e ../datajoint-python/
# unblock port 80 for the Flask app to run on
EXPOSE 1234
# execute the Flask app
CMD ["python", "run.py"]
Below is how amy app directory looks like
Any help is greatly appreciated.
@DavidMaze is correct in that docker-compose
is most likely the cleanest way to run multiple docker containers side-by-side on your host. Once you become accustomed to its declaration, it actually serves as a great way to document local/prototypical setups.
Have a look here at the reference docker-compose
provided for the datajoint/mysql
image. Specifically in a setup as you shared where you are looking to dockerize datajoint-python
, if your Dockerfile
is located in the same directory as your docker-compose.yml
, you can achieve it simply like this:
version: '2.4'
services:
db:
image: datajoint/mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=simple
networks:
- main
#ports:
# - "3306:3306"
#volumes:
# - ./data:/var/lib/mysql
dj:
build: .
depends_on:
db:
condition: service_healthy
environment:
- DJ_HOST=db
- DJ_USER=root
- DJ_PASS=simple
networks:
- main
networks:
main:
Note: The only reason I've intentionally utilized a 2.X
docker-compose
version is that 3.X
versions are meant for Docker Swarm deployments where granular checks like these are unneeded.
这篇关于使用docker映像通过dockerfile构建其他docker映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!