LoginSignup
0
4

More than 5 years have passed since last update.

開発でのDocker①

Posted at

はじめてのDockerの続き

やること

  • Hello World Webアプリ
  • DEV環境がflask単体起動、PRODUCT環境がwsgi+flaskで起動

Hello World Webアプリ用意

# mkdir -p identidock/app
# cd identidock
# vi app/identidock.py
from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello Docker!\n'

if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0')

Dockerfile

# vi Dockerfile
FROM python:3.4

RUN groupadd -r uwsgi && useradd -r -g uwsgi uwsgi
RUN pip install Flask==0.10.1 uWSGI==2.0.8
WORKDIR /app
COPY app /app
COPY cmd.sh /

EXPOSE 9090 9191
USER uwsgi

CMD ["/cmd.sh"]
# vi cmd.sh
#!/bin/bash
set -e

if [ "$ENV" = 'DEV' ]; then
  echo "Running Development Server"
  exec python "identidock.py"
else
  echo "Running Production Server"
  exec uwsgi --http 0.0.0.0:9090 --wsgi-file /app/identidock.py --callable app --stats 0.0.0.0:9191
fi
# chmod +x cmd.sh

起動

# docker run -e "ENV=DEV" -p 5000:5000 identidock

Composeを使った自動化

install

# sh -c "curl -L https://github.com/docker/compose/releases/download/1.5.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose"
# chmod +x /usr/local/bin/docker-compose

docker-compose.yml

# vi docker-compose.yml
identidock:
  build: .
  ports:
    - "5000:5000"
  environment:
    ENV: DEV
  volumes:
    - ./app:/app

起動

# docker-compose up
0
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
4