my Linux containers run like a charm, but the change to Windows Server in my Docker container makes me crazy!
My Docker file doesn't build although it is as simple as my linux Dockerfiles:
FROM microsoft/windowsservercore
#Install Chocolately
RUN #powershell -NoProfile -ExecutionPolicy unrestricted -Command "(iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex)"
ENV PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
#Install python
RUN choco install -fy python2
RUN refreshenv
ENV PYTHONIOINPUT=UTF-8
RUN pip install -y scipy
Some times I was able to Chocolately which results in a fail to install scipy via PIP or curiously starting 5 minutes ago, even the installation of chocolately fails:
iwr : The remote name could not be resolved: 'chocolatey.org'
At line:1 char:2
+ (iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:Htt
pWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShe
ll.Commands.InvokeWebRequestCommand
Here are some specs on my Docker for Windows Installation:
Containers: 2
Running: 0
Paused: 0
Stopped: 2
Images: 3
Server Version: 1.13.0
Storage Driver: windowsfilter
Windows:
Logging Driver: json-file
Plugins:
Volume: local
Network: l2bridge l2tunnel nat null overlay transparent
Swarm: inactive
Default Isolation: hyperv
Kernel Version: 10.0 14393 (14393.693.amd64fre.rs1_release.1612
Operating System: Windows 10 Education
OSType: windows
Architecture: x86_64
CPUs: 4
Total Memory: 7.903 GiB
Name: xxxx
ID: deleted
Docker Root Dir: C:\ProgramData\Docker
Debug Mode (client): false
Debug Mode (server): true
File Descriptors: -1
Goroutines: 18
System Time: 2017-01-31T16:14:36.3753129+01:00
EventsListeners: 0
Registry: https://index.docker.io/v1/
Experimental: true
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Any ideas?
I was unable to get refreshenv to work, so I used multiple powershell sessions, I've included in case it is useful to someone in the future.
#Install Chocolately, Python and Python Package Manager, each PowerShell session will reload the PATH from previous step
RUN #powershell -NoProfile -ExecutionPolicy unrestricted -Command "iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex"
RUN #powershell -NoProfile -ExecutionPolicy unrestricted -Command "choco install -y python3"
Related
I am attempting to perform an SQL query using oracle-instantclient-basic-21.5 through an Ubuntu 20.04.3 agent hosted by Azure Devops. The query itself (which reads: python query_data) works when I am running it on my own machine with specs:
Windows 10
Path=C:\oracle\product\11.2.0.4\client_x64\bin;...;...
TNS_ADMIN=C:\oracle\product\tns
Python 3.8.5 using sqlalchemy with driver="oracle" and dialect = "cx_oracle"
I am running the following:
pool:
vmImage: 'ubuntu-latest'
steps:
- script: |
sudo apt install alien
displayName: 'Install alien'
- script: |
sudo alien -i oracle-instantclient-basic-21.5.0.0.0-1.x86_64.rpm
displayName: 'Install oracle-instantclient-basic'
- script: |
sudo sh -c 'echo /usr/lib/oracle/21/client64/ > /etc/ld.so.conf.d/oracle-instantclient.conf'
sudo ldconfig
displayName: 'Update the runtime link path'
- script: |
sudo cp tns/TNSNAMES.ORA /usr/lib/oracle/21/client64/lib/network/admin
sudo cp tns/ldap.ORA /usr/lib/oracle/21/client64/lib/network/admin
sudo cp tns/SQLNET.ORA /usr/lib/oracle/21/client64/lib/network/admin
sudo cp tns/krb5.conf /usr/lib/oracle/21/client64/lib/network/admin
displayName: 'Copy and paste correct TNS content'
- task: UsePythonVersion#0
inputs:
versionSpec: '3.8'
- script: |
export ORACLE_HOME=/usr/lib/oracle/21/client64
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export TNS_ADMIN=$ORACLE_HOME/lib/network/admin
python query_data
displayName: 'Attempt to run python script with locally valid environment variables'
with the error TNS:could not resolve the connect identifier specified. What I have done:
Checked that the locations I am referring to match the actual oracle-instantclient-basic installation
Copied the TNSNAMES.ORA, ldap.ORA etc. that I am using on my own machine and verified that they are present in the desired location (/usr/lib/oracle/21/client64/lib/network/admin)
Checked that TNS_ADMIN points to the correct path (/usr/lib/oracle/21/client64/lib/network/admin)
The sql query does not complain about a missing client, so it is aware of the installation. Why doesn't it read the TNS_ADMIN path or its contents correctly?
On Linux change the file names to lowercase tnsnames.ora and sqlnet.ora and ldap.ora. If you run, say, strace sqlplus a/b#c you can see that is looks for the lowercase names.
With Instant Client, don't set ORACLE_HOME.
There's no need to set LD_LIBRARY_PATH since ldconfig is used
There's no need to set TNS_ADMIN since you have moved the configuration files to the default location.
You can simplify your install by using alien -i --scripts oracle-instantclient-basic-21.5.0.0.0-1.x86_64.rpm This will automatically do the ldconfig step for you.
Hopefully you have installed the Python cx_Oracle module somehow.
When switching from Docker Desktop to colima I encountered problems with setting up Run configuration in Pycharm thru Docker-compose feature.
Example setup
I keep getting this error from Pycharm:
no such service:
container:9200f38c022e09065fbb972683cd8843c6faedf4b722ee573ea34303f604b843:ro
Process finished with exit code 1
Versions:
Colima v 0.3.2
docker-compose v 2.2.3
PyCharm 2021.3.2 (Professional Edition)
I don't have a solution yet but I believe the culprit is that pycharm uses syntax for specifying containers unsupported by your (our) setup.
Pycharm integrates with docker-compose like this:
docker container with helper scripts in volume is created
$ docker ps -a
...
346cc60545f6 aac5779e964d "/bin/sh" Created pycharm_helpers_PY-213.6777.50
it creates it's own overlay. My project docker-compose.yml is version: 2, pycharm's override is:
$ cat /Users/.../Library/Caches/JetBrains/PyCharm2021.3/tmp/docker-compose.override.2.yml
version: "2"
services:
app:
command:
- "python"
- "-V"
entrypoint: ""
environment:
PYTHONUNBUFFERED: "1"
restart: "no"
volumes: []
volumes_from:
- "container:346cc60545f6e7955661fc6f8f578c6f3f871a7330b068cb35224efbee05aae7:ro"
is calls docker-compose with the overlay:
docker-compose \
-f /Users/.../projects/pythonProject1/docker-compose.yml \
-f /Users/.../Library/Caches/JetBrains/PyCharm2021.3/tmp/docker-compose.override.9.yml \
run --rm --no-deps app
Now if I try container: syntax with docker run I get an error:
$ docker run --rm -it \
--volumes-from container:346cc60545f6e7955661fc6f8f578c6f3f871a7330b068cb35224efbee05aae7:ro \
python:3.9 bash
docker: Error response from daemon: invalid mode: 346cc60545f6e7955661fc6f8f578c6f3f871a7330b068cb35224efbee05aae7:ro.
See 'docker run --help'.
With container: prefix removed it works:
$ docker run --rm -it \
--volumes-from 346cc60545f6e7955661fc6f8f578c6f3f871a7330b068cb35224efbee05aae7:ro \
python:3.9 bash
root#0e5ba9104c62:/# mount | grep pycharm
/dev/disk/by-label/data-volume on /opt/.pycharm_helpers type ext4 (ro,relatime)
root#0e5ba9104c62:/# ls /opt/.pycharm_helpers/
Dockerfile docstring_formatter.py pockets pycharm_matplotlib_backend six.py
MathJax epydoc profiler pycodestyle.py sphinxcontrib
__pycache__ extra_syspath.py py2ipnb_converter.py pydev syspath.py
check_all_test_suite.py generator3 py2only python-skeletons third_party
conda_packaging_tool.py icon-robots.txt py3only remote_sync.py tools
coverage_runner packaging_tool.py pycharm rest_runners typeshed
coveragepy pip-20.3.4-py2.py3-none-any.whl pycharm_display setuptools-44.1.1-py2.py3-none-any.whl virtualenv.pyz
But with docker-compose.yml version: 3 I get different error
error during connect: Get "http://unix:2375/Users/.../.colima/docker.sock/v1.24/containers/json?all=1&filters=%7B%22label%22%3A%7B%22com.docker.compose.project%3Dpythonproject1%22%3Atrue%7D%7D&limit=0": dial tcp: lookup unix on 1.1.1.1:53: no such host
Process finished with exit code 1
Pycharm's docker-compose for 3.8 doesn't use container: syntax anymore:
$ cat /Users/.../Library/Caches/JetBrains/PyCharm2021.3/tmp/docker-compose.override.9.yml
version: "3.8"
services:
app:
command:
- "python"
- "-V"
entrypoint: ""
environment:
PYTHONUNBUFFERED: "1"
restart: "no"
volumes:
- "pycharm_helpers_PY-213.6777.50:/opt/.pycharm_helpers"
volumes:
pycharm_helpers_PY-213.6777.50: {}
Wrapper script replacing the overlay with the one with contaner: prefix stripped would likely help us for version: 2, but the problem with version: 3.8 would persist.
yml version works (both in CI and locally inputting script commands manually)
staging:
stage: test
image: foobar/python36-qt
script:
- pip install things...
- export PATH=/root/.local/bin:$PATH
- export DISPLAY=":$(( ( RANDOM % 250 ) + 1 ))"
- Xvfb $DISPLAY -screen 0 1920x1080x16 &
- pytest --ignore src/foobar/tests/gui/functional
tox version does not work (I run it locally with python3 -m tox -rc tox.ini -e foobar -v)
[testenv:foobar]
whitelist_externals =
Xvfb
sh
setenv =
PATH={env:PATH}:/root/.local/bin
DISPLAY=":3"
QT_DEBUG_PLUGINS=1
deps =
pytest
install_command = pip install --extra-index-url https://pypi-ext.foobar.com/simple {opts} {packages}
commands =
sh -c 'Xvfb ":3" -screen 0 1920x1080x16 &'
pytest -sv tests --ignore tests/gui/functional
initial error:
foobar run-test: commands[2] | sh -c 'Xvfb ":3" -screen 0 1920x1080x16 &'
[17538] /home/localadmin/Documents/foobar/src/foobar$ /bin/sh -c 'Xvfb ":3" -screen 0 1920x1080x16 &'
foobar run-test: commands[3] | pytest -sv tests --ignore tests/gui/functional
[17540] /home/localadmin/Documents/foobar/src/foobar$ /home/localadmin/Documents/foobar/src/foobar/.tox/foobar/bin/pytest -sv tests --ignore tests/gui/functional
_XSERVTransSocketUNIXCreateListener: ...SocketCreateListener() failed
_XSERVTransMakeAllCOTSServerListeners: server already running
(EE)
Fatal server error:
(EE) Cannot establish any listening sockets - Make sure an X server isn't already running(EE)
resulting error:
qt.qpa.xcb: could not connect to display ":3"
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
The first thing I need to solve is why I constantly get _XSERVTransMakeAllCOTSServerListeners: server already running. Before I select a number X in Display=":X", I check /tmp and /tmp/.X11-unix to make sure no X screen exists, and remove it if it does.
I thought maybe I need to run them in the same command (I figure the [17538] and [17540] are processes (?)). No dice
Don't get me wrong, virtualenv (or pyenv) is a great tool, and the whole concept of virtual environments is a great improvement on developer environments, mitigating the whole Snowflake Server anti-pattern.
But nowadays Docker containers are everywhere (for good reasons) and it feels odd having your application running on a container but also setting up a local virtual environment for running tests and such in the IDE.
I wonder if there's a way we could leverage Docker containers for this purpose?
Summary
Yes, there's a way to achieve this. By configuring a remote Python interpreter and a "sidecar" Docker container.
This Docker container will have:
A volume mounted to your source code (henceforth, /code)
SSH setup
SSH enabled for the root:password credentials and the root user allowed to login
Get the sidecar container ready
The idea here is to duplicate your app's container and add SSH abilities to it. We'll use docker-compose to achieve this:
docker-compose.yml:
version: '3.3'
services:
dev:
build:
context: .
dockerfile: Dockerfile.dev
ports:
- 127.0.0.1:9922:22
volumes:
- .:/code/
environment:
DEV: 'True'
env_file: local.env
Dockerfile.dev
FROM python:3.7
ENV PYTHONUNBUFFERED 1
WORKDIR /code
# Copying the requirements, this is needed because at this point the volume isn't mounted yet
COPY requirements.txt /code/
# Installing requirements, if you don't use this, you should.
# More info: https://pip.pypa.io/en/stable/user_guide/
RUN pip install -r requirements.txt
# Similar to the above, but with just the development-specific requirements
COPY requirements-dev.txt /code/
RUN pip install -r requirements-dev.txt
# Setup SSH with secure root login
RUN apt-get update \
&& apt-get install -y openssh-server netcat \
&& mkdir /var/run/sshd \
&& echo 'root:password' | chpasswd \
&& sed -i 's/\#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
Setting up PyCharm Professional Edition
Preferences (CMD + ,) > Project Settings > Project Interpreter
Click on the gear icon next to the "Project Interpreter" dropdown > Add
Select "SSH Interpreter" > Host: localhost, Port: 9922, Username: root > Password: password > Interpreter: /usr/local/bin/python, Sync folders: Project Root -> /code, Disable "Automatically upload..."
Confirm the changes and wait for PyCharm to update the indexes
Setting up Visual Studio Code
Install the Python extension
Install the Remote - Containers extension
Open the Command Pallette and type Remote-Containers, then select the Attach to Running Container... and selecet the running docker container
VS Code will restart and reload
On the Explorer sidebar, click the open a folder button and then enter /code (this will be loaded from the remote container)
On the Extensions sidebar, select the Python extension and install it on the container
When prompet on which interppreter to use, select /usr/local/bin/python
Open the Command Pallette and type Python: Configure Tests, then select the unittest framework
TDD Enablement
Now that you can run your tests directly from your IDE, use it to try out Test-Driven-Develop! One of its key points is a fast feedback loop, and not having to wait for the full test suite to finish execution just to see if your new test is passing is great! Just write it and run it right away!
Reference
The contents of this answer are also available in this GIST.
I had an issue recently after successfully installing and testing Tensorflow compiled with GPU support.
After rebooting the machine, I got the following error Message when I tried to run a Tensorflow program:
...
('Extracting', 'MNIST_data/t10k-labels-idx1-ubyte.gz')
modprobe: FATAL: Module nvidia-uvm not found in directory /lib/modules/4.4.0-34-generic
E tensorflow/stream_executor/cuda/cuda_driver.cc:491] failed call to cuInit: CUDA_ERROR_UNKNOWN
I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:140] kernel driver does not appear to be running on this host (caffe-desktop): /proc/driver/nvidia/version does not exist
I tensorflow/core/common_runtime/gpu/gpu_init.cc:92] No GPU devices available on machine.
(0, 114710.45)
(1, 95368.891)
...
(98, 56776.922)
(99, 57289.672)
Screencapture of error
Code: https://github.com/llSourcell/autoencoder_demo
Question: Why would restarting a Ubuntu 16.04 machine break Tensorflow?
I actually solved my own problem and wanted to share the solution which worked for me.
The magic Google search was:
"modprobe: FATAL: Module nvidia-uvm not found in directory /lib/modules/"
Which led me to the following answer on askubuntu:
https://askubuntu.com/a/496146
That answer's author, Sneetsher, did a really good job of explaining so if the link doesn't 404 I would start there.
Cliff Notes
Diagnosis: I suspected that Ubuntu may have installed a kernel update when I rebooted.
Solution: Reinstalling the NVIDIA driver fixed the error.
Problem: NVIDIA drivers cannot be installed with X server running
Two different ways to fix the NVIDIA Driver
1) Keyboard and Monitor:
Paraphrasing the askubuntu answer:
1) Switch to text-only console (Ctrl+Alt+F1 or any to F6).
2) Build driver modules for the current kernel (which just installed) sudo ./<DRIVER>.run -K
credit "Sneetsher" : https://askubuntu.com/a/496146
I don't have a keyboard or monitor attached to this PC so here's the "headless" approach I actually used:
2) Over SSH:
Following this guide to reboot to console:
http://ubuntuhandbook.org/index.php/2014/01/boot-into-text-console-ubuntu-linux-14-04/
$ sudo cp -n /etc/default/grub /etc/default/grub.orig
$ sudo nano /etc/default/grub
$ sudo update-grub
edit the grub file according to above link(3 changes):
Comment the line GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash”, by adding # at the beginning, which will disable the Ubuntu purple screen.
Change GRUB_CMDLINE_LINUX=”" to GRUB_CMDLINE_LINUX=”text”, this makes Ubuntu boot directly into Text Mode.
Uncomment this line #GRUB_TERMINAL=console, by removing the # at the beginning, this makes Grub Menu into real black & white Text Mode (without background image)
UPDATE: (If running Ubuntu 16.04 If
$ sudo systemctl set-default multi-user.target
Reboot into console
$ sudo shutdown -r now
$ sudo service lightdm stop
$ sudo ./<DRIVER>.run
follow the NVIDIA driver installer
$ sudo mv /etc/default/grub /etc/default/grub.textonly
$ sudo mv /etc/default/grub.orig /etc/default/grub
$ sudo update-grub
$ sudo shutdown -r now
Results (What things look like now the GPU was successfully detected)
...
('Extracting', 'MNIST_data/t10k-labels-idx1-ubyte.gz')
I tensorflow/core/common_runtime/gpu/gpu_init.cc:118] Found device 0 with properties:
name: GeForce GTX 970
major: 5 minor: 2 memoryClockRate (GHz) 1.342
pciBusID 0000:01:00.0
Total memory: 3.94GiB
Free memory: 3.88GiB
I tensorflow/core/common_runtime/gpu/gpu_init.cc:138] DMA: 0
I tensorflow/core/common_runtime/gpu/gpu_init.cc:148] 0: Y
I tensorflow/core/common_runtime/gpu/gpu_device.cc:868] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 970, pci bus id: 0000:01:00.0)
(0, 113040.92)
(1, 94895.867)
...
Screencapture of the same
One simple solution to "Problem: NVIDIA drivers cannot be installed with X server running:
Access ubuntu from another computer using SSH
Remove the screen (display device) of Ubuntu computer
Reboot computer using sudo reboot, then access it again