2

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

enter image description here

Any help is greatly appreciated.

rene
  • 41,474
  • 78
  • 114
  • 152
ishaan arora
  • 523
  • 8
  • 18
  • You can't run `docker` commands in a Dockerfile, at all, and in any case the image basically only contains a filesystem and doesn't persist any running processes. Are you looking for a Docker Compose setup that can start your application and the database together? – David Maze Mar 16 '20 at 00:44
  • Without docker, I start my sql using docker run. And the app uses makes call the database . I want the same thing now when I run the docker image of the entire app + db packaged stuff. So should I do it using docker compose ? – ishaan arora Mar 16 '20 at 00:55
  • Yes, Docker Compose is a standard tool for running multiple containers together. – David Maze Mar 16 '20 at 11:24

1 Answers1

0

@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.

Raphael Guzman
  • 220
  • 2
  • 7