How to run the Docker image using docker-compose? [duplicate]












0
















This question already has an answer here:




  • Deploying docker-compose containers

    1 answer




I have Flask application running under Docker Compose with 2 containers one for Flask and the other one for Nginx.



I am able to run the Flask successfully using docker-compose up --build -d command in my local machine.



What I want is, to save the images into .tar.gz file and move them to the production server and run them automatically. I have used below Bash script to save the Flask and Nginx into one image successfully.



#!/bin/bash

for img in $(docker-compose config | awk '{if ($1 == "image:") print $2;}'); do
images="$images $img"
done

docker save $images | gzip -c > flask_image.tar.gz


I then moved this image flask_image.tar.gz to my production server where Docker installed and used below command to load the image and run the containers.



docker load -i flask_image.ta.gz


This command loaded every layer and loaded the image into my production server. But containers are not up which is expected, since I used only load command.



My question is, is there any command that can load the image and up the containers automatically?



docker-compose.yml



version: '3'

services:

api:
container_name: flask
image: flask_img
restart: always
build: ./app
volumes:
- ~/docker_data/api:/app/uploads
ports:
- "8000:5000"
command: gunicorn -w 1 -b :5000 wsgi:app -t 900

proxy:
container_name: nginx
image: proxy_img
restart: always
build: ./nginx
volumes:
- ~/docker_data/nginx:/var/log/nginx/
ports:
- "85:80"
depends_on:
- api









share|improve this question















marked as duplicate by halfer, Matthieu Brucher, tripleee, Community Nov 23 '18 at 9:10


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Images are already composed of tarballs but have extra data too. Instead of trying to tar an image, have you considered pushing your images to a docker registry? Docker hub is one option, google cloud and aws and azure also have registries to use if you're on those clouds. As a DevOps engineer I would consider it crazy to try to distribute docker images any other way.

    – Dan Farrell
    Nov 21 '18 at 17:00











  • Can you please update some links on how to do it with docker registry. FYI, I have pushed my image to docker hub.

    – Reddi Mohan
    Nov 21 '18 at 17:05
















0
















This question already has an answer here:




  • Deploying docker-compose containers

    1 answer




I have Flask application running under Docker Compose with 2 containers one for Flask and the other one for Nginx.



I am able to run the Flask successfully using docker-compose up --build -d command in my local machine.



What I want is, to save the images into .tar.gz file and move them to the production server and run them automatically. I have used below Bash script to save the Flask and Nginx into one image successfully.



#!/bin/bash

for img in $(docker-compose config | awk '{if ($1 == "image:") print $2;}'); do
images="$images $img"
done

docker save $images | gzip -c > flask_image.tar.gz


I then moved this image flask_image.tar.gz to my production server where Docker installed and used below command to load the image and run the containers.



docker load -i flask_image.ta.gz


This command loaded every layer and loaded the image into my production server. But containers are not up which is expected, since I used only load command.



My question is, is there any command that can load the image and up the containers automatically?



docker-compose.yml



version: '3'

services:

api:
container_name: flask
image: flask_img
restart: always
build: ./app
volumes:
- ~/docker_data/api:/app/uploads
ports:
- "8000:5000"
command: gunicorn -w 1 -b :5000 wsgi:app -t 900

proxy:
container_name: nginx
image: proxy_img
restart: always
build: ./nginx
volumes:
- ~/docker_data/nginx:/var/log/nginx/
ports:
- "85:80"
depends_on:
- api









share|improve this question















marked as duplicate by halfer, Matthieu Brucher, tripleee, Community Nov 23 '18 at 9:10


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Images are already composed of tarballs but have extra data too. Instead of trying to tar an image, have you considered pushing your images to a docker registry? Docker hub is one option, google cloud and aws and azure also have registries to use if you're on those clouds. As a DevOps engineer I would consider it crazy to try to distribute docker images any other way.

    – Dan Farrell
    Nov 21 '18 at 17:00











  • Can you please update some links on how to do it with docker registry. FYI, I have pushed my image to docker hub.

    – Reddi Mohan
    Nov 21 '18 at 17:05














0












0








0









This question already has an answer here:




  • Deploying docker-compose containers

    1 answer




I have Flask application running under Docker Compose with 2 containers one for Flask and the other one for Nginx.



I am able to run the Flask successfully using docker-compose up --build -d command in my local machine.



What I want is, to save the images into .tar.gz file and move them to the production server and run them automatically. I have used below Bash script to save the Flask and Nginx into one image successfully.



#!/bin/bash

for img in $(docker-compose config | awk '{if ($1 == "image:") print $2;}'); do
images="$images $img"
done

docker save $images | gzip -c > flask_image.tar.gz


I then moved this image flask_image.tar.gz to my production server where Docker installed and used below command to load the image and run the containers.



docker load -i flask_image.ta.gz


This command loaded every layer and loaded the image into my production server. But containers are not up which is expected, since I used only load command.



My question is, is there any command that can load the image and up the containers automatically?



docker-compose.yml



version: '3'

services:

api:
container_name: flask
image: flask_img
restart: always
build: ./app
volumes:
- ~/docker_data/api:/app/uploads
ports:
- "8000:5000"
command: gunicorn -w 1 -b :5000 wsgi:app -t 900

proxy:
container_name: nginx
image: proxy_img
restart: always
build: ./nginx
volumes:
- ~/docker_data/nginx:/var/log/nginx/
ports:
- "85:80"
depends_on:
- api









share|improve this question

















This question already has an answer here:




  • Deploying docker-compose containers

    1 answer




I have Flask application running under Docker Compose with 2 containers one for Flask and the other one for Nginx.



I am able to run the Flask successfully using docker-compose up --build -d command in my local machine.



What I want is, to save the images into .tar.gz file and move them to the production server and run them automatically. I have used below Bash script to save the Flask and Nginx into one image successfully.



#!/bin/bash

for img in $(docker-compose config | awk '{if ($1 == "image:") print $2;}'); do
images="$images $img"
done

docker save $images | gzip -c > flask_image.tar.gz


I then moved this image flask_image.tar.gz to my production server where Docker installed and used below command to load the image and run the containers.



docker load -i flask_image.ta.gz


This command loaded every layer and loaded the image into my production server. But containers are not up which is expected, since I used only load command.



My question is, is there any command that can load the image and up the containers automatically?



docker-compose.yml



version: '3'

services:

api:
container_name: flask
image: flask_img
restart: always
build: ./app
volumes:
- ~/docker_data/api:/app/uploads
ports:
- "8000:5000"
command: gunicorn -w 1 -b :5000 wsgi:app -t 900

proxy:
container_name: nginx
image: proxy_img
restart: always
build: ./nginx
volumes:
- ~/docker_data/nginx:/var/log/nginx/
ports:
- "85:80"
depends_on:
- api




This question already has an answer here:




  • Deploying docker-compose containers

    1 answer








docker nginx flask docker-compose dockerfile






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 8:51









halfer

14.7k758115




14.7k758115










asked Nov 21 '18 at 16:56









Reddi MohanReddi Mohan

538




538




marked as duplicate by halfer, Matthieu Brucher, tripleee, Community Nov 23 '18 at 9:10


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by halfer, Matthieu Brucher, tripleee, Community Nov 23 '18 at 9:10


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Images are already composed of tarballs but have extra data too. Instead of trying to tar an image, have you considered pushing your images to a docker registry? Docker hub is one option, google cloud and aws and azure also have registries to use if you're on those clouds. As a DevOps engineer I would consider it crazy to try to distribute docker images any other way.

    – Dan Farrell
    Nov 21 '18 at 17:00











  • Can you please update some links on how to do it with docker registry. FYI, I have pushed my image to docker hub.

    – Reddi Mohan
    Nov 21 '18 at 17:05



















  • Images are already composed of tarballs but have extra data too. Instead of trying to tar an image, have you considered pushing your images to a docker registry? Docker hub is one option, google cloud and aws and azure also have registries to use if you're on those clouds. As a DevOps engineer I would consider it crazy to try to distribute docker images any other way.

    – Dan Farrell
    Nov 21 '18 at 17:00











  • Can you please update some links on how to do it with docker registry. FYI, I have pushed my image to docker hub.

    – Reddi Mohan
    Nov 21 '18 at 17:05

















Images are already composed of tarballs but have extra data too. Instead of trying to tar an image, have you considered pushing your images to a docker registry? Docker hub is one option, google cloud and aws and azure also have registries to use if you're on those clouds. As a DevOps engineer I would consider it crazy to try to distribute docker images any other way.

– Dan Farrell
Nov 21 '18 at 17:00





Images are already composed of tarballs but have extra data too. Instead of trying to tar an image, have you considered pushing your images to a docker registry? Docker hub is one option, google cloud and aws and azure also have registries to use if you're on those clouds. As a DevOps engineer I would consider it crazy to try to distribute docker images any other way.

– Dan Farrell
Nov 21 '18 at 17:00













Can you please update some links on how to do it with docker registry. FYI, I have pushed my image to docker hub.

– Reddi Mohan
Nov 21 '18 at 17:05





Can you please update some links on how to do it with docker registry. FYI, I have pushed my image to docker hub.

– Reddi Mohan
Nov 21 '18 at 17:05












1 Answer
1






active

oldest

votes


















0














Since you mention you already are pushing the docker image to Docker Hub, that means the image has a dockerhub tag that you can use to pull it also.



Usually I use something like this to pull images that are on a registry:



docker run --rm -d --restart=always -p 80:8080 my-dockerhub-user/my-image-name:my-tag



which would run the container in daemon mode and restart if it were to fail. That's just an example; you'd want the ports to align with whatever flask is listening on (8080 in my example) and and the what your server should be listening on (80 in my example).



The server will automatically pull the image down and run it. You can use tags to promote new images, but in that case you'll have to kill the old container as well.






share|improve this answer


























  • since i am using flask and nginx, and mapping the ports. I am not sure If this idea works. I have updated my docker-compose.yml file

    – Reddi Mohan
    Nov 21 '18 at 17:16




















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Since you mention you already are pushing the docker image to Docker Hub, that means the image has a dockerhub tag that you can use to pull it also.



Usually I use something like this to pull images that are on a registry:



docker run --rm -d --restart=always -p 80:8080 my-dockerhub-user/my-image-name:my-tag



which would run the container in daemon mode and restart if it were to fail. That's just an example; you'd want the ports to align with whatever flask is listening on (8080 in my example) and and the what your server should be listening on (80 in my example).



The server will automatically pull the image down and run it. You can use tags to promote new images, but in that case you'll have to kill the old container as well.






share|improve this answer


























  • since i am using flask and nginx, and mapping the ports. I am not sure If this idea works. I have updated my docker-compose.yml file

    – Reddi Mohan
    Nov 21 '18 at 17:16


















0














Since you mention you already are pushing the docker image to Docker Hub, that means the image has a dockerhub tag that you can use to pull it also.



Usually I use something like this to pull images that are on a registry:



docker run --rm -d --restart=always -p 80:8080 my-dockerhub-user/my-image-name:my-tag



which would run the container in daemon mode and restart if it were to fail. That's just an example; you'd want the ports to align with whatever flask is listening on (8080 in my example) and and the what your server should be listening on (80 in my example).



The server will automatically pull the image down and run it. You can use tags to promote new images, but in that case you'll have to kill the old container as well.






share|improve this answer


























  • since i am using flask and nginx, and mapping the ports. I am not sure If this idea works. I have updated my docker-compose.yml file

    – Reddi Mohan
    Nov 21 '18 at 17:16
















0












0








0







Since you mention you already are pushing the docker image to Docker Hub, that means the image has a dockerhub tag that you can use to pull it also.



Usually I use something like this to pull images that are on a registry:



docker run --rm -d --restart=always -p 80:8080 my-dockerhub-user/my-image-name:my-tag



which would run the container in daemon mode and restart if it were to fail. That's just an example; you'd want the ports to align with whatever flask is listening on (8080 in my example) and and the what your server should be listening on (80 in my example).



The server will automatically pull the image down and run it. You can use tags to promote new images, but in that case you'll have to kill the old container as well.






share|improve this answer















Since you mention you already are pushing the docker image to Docker Hub, that means the image has a dockerhub tag that you can use to pull it also.



Usually I use something like this to pull images that are on a registry:



docker run --rm -d --restart=always -p 80:8080 my-dockerhub-user/my-image-name:my-tag



which would run the container in daemon mode and restart if it were to fail. That's just an example; you'd want the ports to align with whatever flask is listening on (8080 in my example) and and the what your server should be listening on (80 in my example).



The server will automatically pull the image down and run it. You can use tags to promote new images, but in that case you'll have to kill the old container as well.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 23 '18 at 8:53









halfer

14.7k758115




14.7k758115










answered Nov 21 '18 at 17:14









Dan FarrellDan Farrell

6,14711417




6,14711417













  • since i am using flask and nginx, and mapping the ports. I am not sure If this idea works. I have updated my docker-compose.yml file

    – Reddi Mohan
    Nov 21 '18 at 17:16





















  • since i am using flask and nginx, and mapping the ports. I am not sure If this idea works. I have updated my docker-compose.yml file

    – Reddi Mohan
    Nov 21 '18 at 17:16



















since i am using flask and nginx, and mapping the ports. I am not sure If this idea works. I have updated my docker-compose.yml file

– Reddi Mohan
Nov 21 '18 at 17:16







since i am using flask and nginx, and mapping the ports. I am not sure If this idea works. I have updated my docker-compose.yml file

– Reddi Mohan
Nov 21 '18 at 17:16







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()