Run multiple services in one docker container
Tag: Ruby
Tag: Rails
Category: jekyll
Category: update
Category: git
Category: database
Category: PostgreSQL
Category: websocket
Category: ruby
Category: projects
Category: Redis
Category: mysql
Category: Mac
Category: Node
Category: NPM
Category: PM2
Category: nodejs
Category: Meteor
Category: Nginx
Category: gitLab
Category: Rails
- Why Ruby on Rails is better than Python Django?
- How to use Hotwire turbo in Rails 6 with Webpacker?
- Rails 6 Credentials (master.key and credentials.yml.enc)
- Rails Console
- JIRA-Atlassian-Connect-App-Django
- Rails 4 5.0 Session Cookie AuthenticityToken
- Rails Active Storage
- Rails 5 Source code Research
- 微信支付
- Rails零星笔记
Category: Homebrew
Category: CentOS
Category: FreeSwitch
Category: Ruby
- Ruby on Rails 8
- RESTful API
- Ruby on Rails 7
- Study from Ruby official website
- Ruby-Metaprogramming
- Ruby连数据库的问题
- rbenv使用
Category: Vim
Category: javascript
Category: React-Native
Category: Wechat
Category: homeland
Category: JavaScript
Category: Docker
Category: RubyMine
Category: Authorization
Category: RESTful-API
Category: Proxy
Category: Deploy
Category: Devise
Category: Bootstrap
Category: Active_Storage
Category: github
Category: Android
Category: cloud
Category: ssh
Category: python
Category: reactjs
Category: markdown
Category: ShadowSocks
Category: Code
Category: rails
Category: code
Category: Django
Category: Python
Category: DRF
Category: Fish
Category: Yarn
Category: Material-UI
Category: CSS
Category: aws
Category: uwsgi
Category: nginx
Category: docker
Category: React
Category: Enzyme
Category: Jira
Category: Interview
Category: JetBrain
Category: PyCharm
Category: ESLint
Category: Rails6
Category: NVM
Category: ssl
Category: tencent
Category: CI
Category: jenkins
Category: GitHub
Category: Credentials
Category: master.key
Category: Webpacker
Category: Turbo
Category: Hotwire
Category: Bootstrap5
Category: Flutter
Category: Clash
Category: Tor
Category: proxy
Category: Build
Category: SwitchyOmega
Category: Chrome-extension
Category: SQLAlchemy
Category: Algorithm
Category: Rails7
Category: Data
Category: Structure
Category: CPP
Category: Languages
Category: Golang
Category: Typescript
Category: Rails 8
Notice
- You should read the previous article
2020-06-08 Mac-Django-uwsgi-Nginx
first.
Sometimes you have the need to use only one container but run all the services which are implemented by docker-compose.
How can we do it without using docker-compose
but with only one Dockerfile
?
We need to use install all these services in one image and use Supervised
to start all the services.
The example, we have a django project started by uWSGI and a Nginx.
Please see my previous article to see how to make them work on your local machine first.
Then the second step will be the docker part.
Dockerfile
FROM tiangolo/uwsgi-nginx:python3.8
ENV PYTHONUNBUFFERED 1
RUN rm -rf /app/*
COPY ./config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY ./config/mysite_nginx.conf /etc/nginx/conf.d/mysite_nginx.conf
COPY ./config/uwsgi.ini /app/uwsgi.ini
RUN groupadd -r django \
&& useradd -r -g django django
COPY ./api/requirements.frozen /requirements.frozen
RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r /requirements.frozen \
&& rm /requirements.frozen
COPY ./compose/production/django/uwsgi.sh /uwsgi.sh
RUN sed -i 's/\r//' /uwsgi.sh
RUN chmod +x /uwsgi.sh
RUN chown django /uwsgi.sh
COPY ./api /app
WORKDIR /app
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
ENTRYPOINT ["/entrypoint.sh"]
EXPOSE 8000
supervisord
pip install supervisor
supervisord -n
touch supervisord.conf
```ini [supervisord] nodaemon=true
[program:uwsgi] command=/uwsgi.sh stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stdout stderr_logfile_maxbytes=0
[program:nginx] command=/usr/sbin/nginx stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0
## Docker
* In Docker container, if you want to connect to Database in Host, you can use:
`host.docker.internal`
* `docker run --publish 80:8000 --env-file .env --detach --name container5 built2`
* `touch ./compose/production/django/uwsgi.sh`
```shell script
#!/usr/bin/env bash
set -o errexit
set -o pipefail
set -o nounset
cd /app
python manage.py collectstatic --noinput
python manage.py migrate
/usr/local/bin/uwsgi --ini /app/uwsgi.ini --die-on-term
- The image even don’t have
vi
command. So sometimes you need to replace words in a file bysed -i 's/8000/80/' mysite_nginx.conf