Menu
  • Home
  • About Me
  • Blog
  • Github
  • LinkedIn

Python for Algorithmic Trading – Conda as a Package Manager in Docker (2)

January 31, 2022

Python for Algorithmic Trading (1)

Docker Container

This section goes into the details of what the docker technology can do in the context of Python deployment.

Building a Ubuntu and Python Docker Image

This dockerfile control the building procedure for the image itself. The Bash script in below will be installing three parts:

  • Linux housekeeping
  • Miniconda
  • optional Python packages

Script installing Python and optional packages

#!/bin/bash
#
# Script to Install
# Linux System Tools and
# Basic Python Components
#
# Python for Algorithmic Trading
# (c) Dr. Yves J. Hilpisch
# The Python Quants GmbH
#
# GENERAL LINUX
apt-get update # updates the package index cache
apt-get upgrade -y # updates packages
# installs system tools
apt-get install -y bzip2 gcc git # system tools
apt-get install -y htop screen vim wget # system tools
apt-get upgrade -y bash # upgrades bash if necessary
apt-get clean # cleans up the package index cache
# INSTALL MINICONDA
# downloads Miniconda
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O \
 Miniconda.sh
bash Miniconda.sh -b # installs it
rm -rf Miniconda.sh # removes the installer
export PATH="/root/miniconda3/bin:$PATH" # prepends the new path
# INSTALL PYTHON LIBRARIES
conda install -y pandas # installs pandas
conda install -y ipython # installs IPython shell
# CUSTOMIZATION
cd /root/
wget http://hilpisch.com/.vimrc # Vim configuration

Dockerfile to build the image

FROM ubuntu:latest
# information about maintainer
MAINTAINER sean
# add the bash script
ADD install_miniconda.sh /
# change rights for the script
RUN chmod u+x /install_miniconda.sh
# run the bash script
RUN /install_miniconda.sh
# prepend the new path
ENV PATH /root/miniconda3/bin:$PATH
# execute IPython when container is run
CMD ["ipython"]

To do that, I’m going to create a folder on my computer(host)

git clone https://github.com/sikgyu/trading_algo.git

cd trading_algo

docker build -t pyalgo:basic .

# Docker images can be listed via docker images
docker images

You have built the image successfully. To run the image:

docker run -it pyalgo:basic

example

Exiting IPython will exit the container as well, since it is the only application running within the container. However, you can detach from a container via the following:

Ctrl+p –> Ctrl+q

you can attach the container by this commnad

docker attach $CONTAINER_ID

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts
  • ChinguTalkBot v0.1.0: Setting up AWS Cognito with CDK for User Authentication
  • Phoenix & Elixir: Fix PostgreSQL connection refused
  • Demo: Git Log with Shell script to create a release notes
  • Metasploit
  • CyberSecurity Lab – Online Password Attack

Archives
  • March 2024
  • May 2023
  • April 2023
  • February 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
Categories
  • Amazon Interview (3)
  • Ansible (3)
  • AWS (9)
  • Azure (9)
  • Certification (2)
  • ChinguTalkBot Project (1)
  • cybersecurity (3)
  • Data analytics (6)
  • Demo Videos (6)
  • Docker (5)
  • Git (1)
  • GitLab (1)
  • Golang (3)
  • JavaScript (2)
  • Jenkins (4)
  • PowerShell (1)
  • Python (10)
  • Terraform (11)
  • Uncategorized (9)

©2025 | Powered by WordPress and Superb Themes!