1

I would like to build a docker image for dumping large SQL Server tables into S3 using the bcp tool by combining this docker and this script. Ideally I could pass table, database, user, password and s3 path as arguments for the docker run command.

The script looks like

#!/bin/bash

TABLE_NAME=$1
DATABASE=$2
USER=$3
PASSWORD=$4
S3_PATH=$5

# read sqlserver...
# write to s3...
# .....

And the Dockerfile is:

# SQL Server Command Line Tools
FROM ubuntu:16.04

LABEL maintainer="SQL Server Engineering Team"

# apt-get and system utilities
RUN apt-get update && apt-get install -y \
    curl apt-transport-https debconf-utils \
    && rm -rf /var/lib/apt/lists/*# SQL Server Command Line Tools
FROM ubuntu:16.04

LABEL maintainer="SQL Server Engineering Team"

# apt-get and system utilities
RUN apt-get update && apt-get install -y \
    curl apt-transport-https debconf-utils \
    && rm -rf /var/lib/apt/lists/*

# adding custom MS repository
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list

# install SQL Server drivers and tools
RUN apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql mssql-tools awscli
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
RUN /bin/bash -c "source ~/.bashrc"

ADD ./sql2sss.sh /opt/mssql-tools/bin/sql2sss.sh
RUN chmod +x /opt/mssql-tools/bin/sql2sss.sh

RUN apt-get -y install locales
RUN locale-gen en_US.UTF-8
RUN update-locale LANG=en_US.UTF-8

ENTRYPOINT ["/opt/mssql-tools/bin/sql2sss.sh", "DB.dbo.TABLE", "SQLSERVERDB", "USER", "PASSWORD", "S3PATH"]

If I replae the entrypoint for CMD /bin/bash and run the image with -it, I can manually run the sql2sss.sh and it works properly, reading and writing to s3. However if I try to use the entrypoint as shown yelds bcp: command not found.

I also noticed if I use CMD /bin/sh in iterative mode it will produce the same error. Am I missing some configuration in order for the entrypoint to run the script properly?

filippo
  • 5,583
  • 13
  • 50
  • 72
  • Most paths through Docker don't read dotfiles like `.bashrc`, so the additional directory isn't winding up in `$PATH`. Does the `ENV PATH=...` setup from [In a Dockerfile, How to update PATH environment variable?](https://stackoverflow.com/questions/27093612/in-a-dockerfile-how-to-update-path-environment-variable) improve things? – David Maze May 09 '22 at 00:13
  • (Also note that anything you set as `ENV VARIABLE=value` in the Dockerfile, or pass as `docker run -e VARIABLE=value`, will be directly readable as `$VARIABLE` in the shell script; this is often easier to set up than trying to pass many positional parameters.) – David Maze May 09 '22 at 00:14

1 Answers1

0

Have you tried

ENV PATH="/opt/mssql-tools/bin:${PATH}"

Instead of exporting the bashrc?

As David Maze pointed out docker doesn't read dot files

Basically add your env definitions in the ENV primitive

Tolis Gerodimos
  • 3,782
  • 2
  • 7
  • 14