-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDocker-Compose: Deploying Django app and Mysql DB.html
1 lines (1 loc) · 2.99 KB
/
Docker-Compose: Deploying Django app and Mysql DB.html
1
<div class="note-header">Docker-Compose: Deploying Django app and Mysql DB</div><div class="step-header">Step: 1 Create a Dockerfile<br></div><div class="description">FROM python:3.6<br>RUN apt-get update<br>RUN apt-get install -y git<br>RUN apt-get install -y libsasl2-dev python-dev libldap2-dev libssl-dev psmisc libpq-dev<br>RUN apt-get -y install python3-pip<br>RUN mkdir /mydir<br>WORKDIR /mydir<br>ADD req.txt /mydir/<br>RUN pip install -r req.txt<br>ADD Katanaframework /mydir/Katanaframework</div><div class="step-header">Step: 2 Create a docker-compose.yml file<br></div><div class="description">version: '3'<br><br>services:<br> db:<br> image: mysql:5.7<br> ports:<br> - '3306:3306'<br> environment:<br> MYSQL_DATABASE: 'my-app-db'<br> MYSQL_USER: 'root'<br> MYSQL_PASSWORD: 'password'<br> MYSQL_ROOT_PASSWORD: 'password'<br> web:<br> build: .<br> command: ls -a<br> command: python Katanaframework/katana/manage.py runserver 0.0.0.0:8000<br> volumes:<br> - .:/mydir<br> ports:<br> - "8000:8000"<br> depends_on:<br> - db<br><br></div><div class="step-header">Step: 3 Create a requirement file and Django app(in this case I am using Katanaframework).<br></div><div class="description"><div>Requirements depends on the django project.</div><div><br></div><div>Note: In yaml file commands like python /mountpath/appcode/manage.py runserver can be there, in this command the path of the manage.py should be a valid.<br></div></div><div class="step-header">Step: 4 Build and Run<br></div><div class="description">To build use sudo docker-compose build<br>To run use sudo docker-compose up<br></div><div class="step-header">Step: 5 Still server is crashing?<br></div><div class="description"><div>It can be a reason that the required tables were not migrated to the Mysql DB,</div><div>Run sudo docker-compose run web python mountpath/appcode/manage.py migrate</div><div><br></div><div>then again fire up the container using sudo docker-compose up</div><div><br></div><div>repeat this until the server runs successfully, and if they are any errors debug and then again run the docker-compose up command.<br><br><br>Note: To run in detached mode use -d flag.<br>example: sudo docker-compose up -d<br></div></div><div class="step-header">Step: 6 Additional Info<br></div><div class="description">To login to mysql db running container:<br><div>sudo docker exec -it <mysql_container_id> bash</div><div><br></div><div>after logging in use: mysql -u root -p (press enter)</div><div>then provide password in this case we have given "password" as password in yaml file.</div><div><br></div><div><br></div></div>