Skip to content
Snippets Groups Projects
Commit 8d006354 authored by Giuliano Taffoni's avatar Giuliano Taffoni
Browse files

add Docker exercises

parent b0683c37
No related branches found
No related tags found
No related merge requests found
Showing
with 234 additions and 0 deletions
# I use CentOS latest
FROM centos:latest
# I set the work directory
WORKDIR /home/mpi4py
# I copy the content of the current dir into /home/mpi4py
COPY . /home/mpi4py
# Install some sw
RUN yum install -y vim wget epel-release
RUN yum install -y gsl gsl-devel gcc gcc-gfortran make autoconf patch automake
RUN yum install -y mpich-3.2 mpich-3.2-devel mpich-3.2-autoload environment-modules
RUN yum install -y python-devel numpy python-matplotlib python2-pip
# I set some env virables
ENV MPI_INCLUDE=/usr/include/mpich-3.2-x86_64
ENV MPI_PYTHON_SITEARCH=/usr/lib64/python2.7/site-packages/mpich-3.2
ENV MPI_LIB=/usr/lib64/mpich-3.2/lib
ENV MPI_BIN=/usr/lib64/mpich-3.2/bin
ENV MPI_COMPILER=mpich-3.2-x86_64
ENV MPI_SYSCONFIG=/etc/mpich-3.2-x86_64
ENV MPI_SUFFIX=_mpich-3.2
ENV MPI_MAN=/usr/share/man/mpich-3.2
ENV MPI_HOME=/usr/lib64/mpich-3.2
ENV MPI_FORTRAN_MOD_DIR=/usr/lib64/gfortran/modules/mpich-3.2-x86_64
ENV PATH="/usr/lib64/mpich-3.2/bin:${PATH}"
# install some python modules
RUN pip install --upgrade pip
RUN pip install mpi4py
RUN pip install astropy
RUN pip install ipython
# Use an official Python runtime as a parent image
FROM python:2.7-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME World
# Run app.py when the container launches
CMD ["python", "main.py"]
from flask import Flask
import os
import socket
visits = 0
app = Flask(__name__)
@app.route("/")
def hello():
try:
with open( "count.txt", "r" ) as f:
count = f.read()
except:
count = 0
html = "<h3>Hello {name}!</h3>" \
"<b>Hostname:</b> {hostname}<br/>" \
"<b>Visits:</b> {visits}"
count = int(count)
with open( "count.txt", "w" ) as f:
f.write( str(count+1) )
return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname(), visits=count)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=80)
Flask
gunicorn
Redis
version: "3"
services:
web:
image: hello_odmec
deploy:
replicas: 5
resources:
limits:
cpus: "0.1"
memory: 50M
restart_policy:
condition: on-failure
ports:
- "4000:80"
networks:
- webnet
networks:
webnet:
# Use an official Python runtime as a parent image
FROM hello_odmec
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME World
# Run app.py when the container launches
CMD ["python", "main.py"]
from flask import Flask
import os
import socket
visits = 0
app = Flask(__name__)
@app.route("/")
def hello():
try:
with open( "/data/count.txt", "r" ) as f:
count = f.read()
except:
count = 0
html = "<h3>Hello {name}!</h3>" \
"<b>Hostname:</b> {hostname}<br/>" \
"<b>Visits:</b> {visits}"
count = int(count)
with open( "/data/count.txt", "w" ) as f:
f.write( str(count+1) )
return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname(), visits=count)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=80)
Flask
gunicorn
Redis
FROM python:3.4-alpine
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD ["python", "main.py"]
version: '3'
services:
web:
build: .
ports:
- "5000:5000"
redis:
image: "redis:alpine"
import time
import redis
from flask import Flask
app = Flask(__name__)
cache = redis.Redis(host='redis', port=6379)
def get_hit_count():
retries = 5
while True:
try:
return cache.incr('hits')
except redis.exceptions.ConnectionError as exc:
if retries == 0:
raise exc
retries -= 1
time.sleep(0.5)
@app.route('/')
def hello():
count = get_hit_count()
return 'Hello World! I have been seen {} times.\n'.format(count)
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True)
flask
redis
docker run --rm -ti ubuntu:latest bash
docker run -ti ubuntu:latest bash
--mount type=bind,source="$(pwd)"/target,target=/app
docker ps -a
docker attach 9ef4536973c7
docker start 9ef4536973c7
docker ps -a
docker attach 9ef4536973c7
docker rm 9ef4536973c7
docker ps -a
export ODMEC="ENV_DATA"
docker run --name ubuntu.test -ti -v $PWD:/data -e ODMEC ubuntu bash
docker run -ti -v /data2 ubuntu:latest bash
root@bbdf070861eb:/# cd /data2/
root@bbdf070861eb:/data2#
# Use an official Python runtime as a parent image
FROM python:2.7-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME World
# Run app.py when the container launches
CMD ["python", "main.py"]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment