Showing posts with label docker. Show all posts
Showing posts with label docker. Show all posts

Sunday, April 19, 2020

How to deploy python programs to Docker

docker python

Running python programs in Docker

It is quite easy to run your python programs in docker. For getting started with python in docker, we need to install docker in our system.

I am using Ubuntu and followed the instruction details beginners commands to start with Docker.

Once you have installed docker, we can start building our docker. We can create a separate folder/directory for this in our system.

FROM tells Docker which image you base your image on (in the example, Python 3).

RUN tells Docker which additional commands to execute.

CMD tells Docker to execute the command when the image loads.

Dockerfile:

#base image
FROM python:3

#adding our first program/application to docker image
ADD app.py /
ADD app2.py /

#this time we are using a script to run our applications.
ADD script.sh /
#make the script executable
RUN ["chmod", "+x", "./script.sh"]
#changed the command to run the script
CMD ./script.sh 
#you can read more about commands in docker at https://docs.docker.com
#add the command instruction
#CMD ["python","./app.py"]

script file:

You can specify your python programs in the script.
Note: I have explicitly used python3 to run the programs.

#!bin/bash

#first process
python3 app.py

#second process
python3 app2.py

Python applications

print("this is my first pythong docker program")

Friday, April 17, 2020

8 beginners commands to start with Docker


Installation guides:


windows - https://docs.docker.com/docker-for-windows/

linux - https://docs.docker.com/engine/install/

mac - https://docs.docker.com/docker-for-mac/install/


docker basic
  1. List currently running docker containers:
    docker ps
  2. List all docker containers (running and stopped):
    docker ps -a
  3. Start a container from an image, with a custom name:
    docker run --name container_name image
  4. Start or stop an existing container:
    docker start|stop container_name
  5. Pull an image from a docker registry:
    docker pull image
  6. Open a shell inside of an already running container:
    docker exec -it container_name sh
  7. Remove a stopped container:
    docker rm container_name
  8. Fetch and follow the logs of a container:
    docker logs -f container_name

Friday, August 7, 2015

How to use Docker ?

First of all , what is docker ?... I came across docker when I was searching for code editor and how to compile C code form web applications.
http://qnimate.com/create-an-frontend-editor-with-code-highlighting-and-execution/

 Docker - https://www.docker.com/

Docker is an open-source project that automates the deployment of applications inside software containers, by providing an additional layer of abstraction and automation of operating-system-level virtualization on Linux. https://en.wikipedia.org/wiki/Docker_(software)

I actually want to run the code in a virtual machine ( for this idea http://naveendavisv.blogspot.com/2015/08/thinking-to-build-microcontroller.html) and show the output in a text area, even though I don't need the full output, but if  the code can be checked for syntax error, I am much happy...