Inside of a docker container I run a python script. My Dockerfile looks as follows
FROM ubuntu:18.04
WORKDIR /ingestion
COPY /services/bcp /ingestion/services/bcp
RUN mkdir -p /tmp/ingestion && \
chmod +x /ingestion/bcp-build.sh && \
/ingestion/bcp-build.sh
ENTRYPOINT ["python3", "-m", "services.bcp"]
Inside of bcp-build.sh I install bcp tool for linux:
apt-get update
apt-get upgrade -y
apt-get install -y curl
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | tee /etc/apt/sources.list.d/msprod.list
apt-get update
ACCEPT_EULA=Y apt-get install -y mssql-tools unixodbc-dev
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bash_profile
source ~/.bashrc
To run the container I use docker-compose.yml
version: "3"
services:
bcp:
build: .
The python (a sample piece of code over here) looks like this:
import argparse
arg_parser: argparse = argparse. \
ArgumentParser(
description="Extract tables to CSV",
usage="bcp.py [-h] [--database [str]]"
)
required_args: argparse = arg_parser.add_argument_group("required arguments")
required_args.add_argument("--database", metavar="str", type=str, help="database from where to extract", required=True)
def foo():
args: argparse = arg_parser.parse_args()
database = args.database
print(database)
# build bcp cmd
cmd: str = f"bcp {database}.table out /tmp/ingestion/foo.csv"
subprocess.run(cmd, shell=True) # execute it via subprocess
foo()
To create the image and use it, I run the following commands, docker-compose up -d --build -t foo. It works. But, when I try to execute python code it does not recognise the bcp command. It says bcp command not found. Could you please instruct, how to mitigate this issue?
The exact error message is "bcp command not found".
Interestingly enough, when I run docker run -it --rm --entrypoint bash foo, and execute bcp then the command is available.