The previous articles about Docker have covered image handling; now we will explain how to import a container from Python. This article is based on the following article in English.
- Installing Docker on Debian Jessie
- Using Docker on Debian Jessie (part 1)
- Using Docker on Debian Jessie (part 2)
- Creating a Docker image from a Dockerfile
- Starting Django using Docker
- Installing Gitlab through Docker
- Running microservices with docker using docker-compose
- Docker in Docker (DinD)
- Starting Django with docker using docker-compose with postgresql as a microservice.
There is the Sidomo module, which lets you manage containers.
To install sidomo, run the pip command:
pip install -e git+https://github.com/deepgram/sidomo.git#egg=sidomo
Download the Ubuntu Docker image:
docker pull ubuntu
The example code from the sidomo site is at the following link.
The modified code is the following:
#!/usr/bin/env python
from sidomo import Container
def say_hello(to):
"""Just say it."""
with Container(
'ubuntu',
stderr=False
) as c:
for line in c.run(
'echo Hola Mundo %s' % to
):
yield line
if __name__ == '__main__':
for line in say_hello("desde un contenedor Docker"):
print line
Running the code gives:
python ejemplo.py
Hola Mundo desde un contenedor Docker
Make a donation! If you liked the article you can make a donation with Bitcoin (BTC) using the digital wallet of your choice to the following address: 17MtNybhdkA9GV3UNS6BTwPcuhjXoPrSzV
Or by scanning the QR code from the wallet:
