DockerのUbuntuコンテナにMSSQLコマンドラインツールをインストール
Docker上のUbuntuからSqlServerへ接続させるため、SQLServerコマンドラインツールをインストールする。
途中、いろいろエラーが発生したのでメモっておく。
Ubuntuバージョン確認
gnupg エラー やっとGPGキーインポートだー、とcurlしたら
Ubuntuバージョン確認
$ cat /etc/os-releaseapt updateエラー apt updateしたらいきなりエラー
$ apt-get update ubuntu E: The method driver /usr/lib/apt/methods/https could not be found. # 解決策 $ apt-get install apt-transport-https
gnupg エラー やっとGPGキーインポートだー、とcurlしたら
E: gnupg, gnupg2 and gnupg1 do not seem to be installed, # 解決策(gnupgがインストールされていないため) $ apt-get update $ apt-get install -y gnupg2
恒久対策としては、Dockerファイルにあらかじめ定義しておくらしい。
ということでDockerファイル更新しておく。FROM ubuntu:18.04 MAINTAINER Aleksandar Diklic "https://github.com/rastasheep" RUN apt-get update RUN apt-get install -y openssh-server RUN mkdir /var/run/sshd RUN echo 'root:root' |chpasswd RUN sed -ri 's/^#?PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config RUN mkdir /root/.ssh RUN apt-get install -y sudo RUN apt-get install -y nginx RUN apt-get install -y vim RUN apt-get install -y curl RUN apt-get update RUN apt-get install -y apt-transport-https RUN apt-get update RUN apt-get install -y gnupg2 RUN apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* EXPOSE 22 EXPOSE 80 EXPOSE 433 CMD ["/usr/sbin/sshd", "-D"]
やっとスタート
SQL Server コマンドライン ツール sqlcmdをインストールする。
1. パブリック リポジトリの GPG キーをインポートします。$ curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - [sudo] password for ubuntu: % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 983 100 983 0 0 1780 0 --:--:-- --:--:-- --:--:-- 1777 OK
2.Microsoft Ubuntu リポジトリを登録します。$ curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 79 100 79 0 0 149 0 --:--:-- --:--:-- --:--:-- 148 deb [arch=amd64] https://packages.microsoft.com/ubuntu/16.04/prod xenial main
3. ソース一覧を更新し、unixODBC 開発者パッケージを使用してインストール コマンドを実行します。
ライセンス承諾を求められます。$ sudo apt-get update $ sudo apt-get install mssql-tools unixodbc-dev
4. 省略可能:bash シェルで PATH 環境変数に /opt/mssql-tools/bin/ を追加します。$ echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile $ source ~/.bash_profile
5.SQLServerのDockerコンテナに外部接続してみる。$ sqlcmd -S 172.17.0.2 -U SA -P "Passw0rd" 1> SELECT Name from sys.Databases 2> GO Name -------------------------------------------------------------------------------------------------------------------------------- master tempdb model msdb TestDB TestIIDA (6 rows affected)つながった!!
参考:Linux に SQL Server コマンドライン ツール sqlcmd および bcp をインストールする
コメント
コメントを投稿