Docker Community Forums

Share and learn in the Docker community.

Linux container docker exec -it container_id /bin/bash works on windows box but not on linux box

Hi,

I am trying to get a image/container up and running on a K8 cluster linux nodes. I am trying to diagnose the issue by trying to run

docker exec -it container_id /bin/bash

on a windows machine with docker in linux container mode, I get the bash shell and can explore inside the container.

on a centos7 machine (a node of the k8 cluster) I am NOT able to do

docker exec -it container_id /bin/bash

or

docker exec -it container_id /bin/sh

i get the error

rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:235: starting container process caused “exec: “//bin//bash”: stat //bin//bash: no such file or directory”

any ideas?

Kubernetes itself gives a shi* about docker and what it brings to the table, actualy it’s happy with any CRI compliant container engine.

Why don’t you just use the tool intended for this purposes instead?
kubectl and its kubectl exec action.

I’m new to docker swarm and am able to deploy my services on various nodes, however, the environment variables that are exported from a dockerfile ENTRYPOINT script are not setting for tasks that are deployed in the docker swarm cluster.

Setup

docker version 18.09.1, build 4c52b90
docker-compose version 1.23.2, build 1110ad01
Django 2.1.5
PosgresSQL 10
Trying to do a one-off command inside a django task, using docker exec -t CONTAINER_ID sh to get into the container, then executing python manage.py migrate, I get the following error:

Error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “manage.py”, line 38, in
execute_from_command_line(sys.argv)
File “/usr/local/lib/python3.6/site-packages/django/core/management/init.py”, line 381, in execute_from_command_line
utility.execute()
File “/usr/local/lib/python3.6/site-packages/django/core/management/init.py”, line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File “/usr/local/lib/python3.6/site-packages/django/core/management/init.py”, line 211, in fetch_command
settings.INSTALLED_APPS
File “/usr/local/lib/python3.6/site-packages/django/conf/init.py”, line 57, in getattr
self._setup(name)
File “/usr/local/lib/python3.6/site-packages/django/conf/init.py”, line 44, in _setup
self._wrapped = Settings(settings_module)
File “/usr/local/lib/python3.6/site-packages/django/conf/init.py”, line 107, in init
mod = importlib.import_module(self.SETTINGS_MODULE)
File “/usr/local/lib/python3.6/importlib/init.py”, line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 994, in _gcd_import
File “”, line 971, in _find_and_load
File “”, line 955, in _find_and_load_unlocked
File “”, line 665, in _load_unlocked
File “”, line 678, in exec_module
File “”, line 219, in _call_with_frames_removed
File “/app/config/settings/production.py”, line 15, in
DATABASES[‘default’] = env.db(‘DATABASE_URL’) # noqa F405
File “/usr/local/lib/python3.6/site-packages/environ/environ.py”, line 202, in db_url
return self.db_url_config(self.get_value(var, default=default), engine=engine)
File “/usr/local/lib/python3.6/site-packages/environ/environ.py”, line 275, in get_value
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: Set the DATABASE_URL environment variable
So, the DATABASE_URL is not set as an environment variable inside my docker container. As stated before, this is exported from an ENTRYPOINT script which is invoked in the dockerfile.

Dockerfile

FROM python:3.6-alpine

ENV PYTHONUNBUFFERED 1

RUN apk update

psycopg2 dependencies

&& apk add --virtual build-deps gcc python3-dev g++ musl-dev
&& apk add postgresql-dev

Pillow dependencies

&& apk add jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev

CFFI dependencies

&& apk add libffi-dev py-cffi

Translations dependencies

&& apk add gettext

https://docs.djangoproject.com/en/dev/ref/django-admin/#dbshell

Requirements are installed here to ensure they will be cached.

COPY ./requirements /requirements
RUN pip install -r /requirements/production.txt
&& rm -rf /requirements

COPY ./compose/production/django/entrypoint /entrypoint
RUN sed -i ‘s/r//’ /entrypoint
RUN chmod +x /entrypoint
RUN chown django /entrypoint

COPY ./compose/production/django/start /start
RUN sed -i ‘s/r//’ /start
RUN chmod +x /start
RUN chown django /start

COPY ./compose/production/django/celery/worker/start /start-celeryworker
RUN sed -i ‘s/r//’ /start-celeryworker
RUN chmod +x /start-celeryworker
RUN chown django /start-celeryworker

COPY ./compose/production/django/celery/beat/start /start-celerybeat
RUN sed -i ‘s/r//’ /start-celerybeat
RUN chmod +x /start-celerybeat
RUN chown django /start-celerybeat

COPY ./compose/production/django/celery/flower/start /start-flower
RUN sed -i ‘s/r//’ /start-flower
RUN chmod +x /start-flower

COPY . /app

RUN chown -R django /app

USER django

WORKDIR /app

ENTRYPOINT ["/entrypoint"]