host not found in upstream error caused by docker-compose - docker

tldr-version: I have no idea whats causing this error. im pretty sure its not the line endings because i changed them manually with notepad++ (unless i need to change more than entrypoint.sh because thats all i changed the line endings on).
original post below.
I have no idea what is causing this error caused when i do docker-compose -f docker-compose-deploy.yml up --build into my command line i get the following output
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
Starting mygoattheend-copy_app_1 ... done
Starting mygoattheend-copy_proxy_1 ... done
Attaching to mygoattheend-copy_app_1, mygoattheend-copy_proxy_1
app_1 | exec /scripts/entrypoint.sh: no such file or directory
proxy_1 | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
proxy_1 | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
proxy_1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
proxy_1 | 10-listen-on-ipv6-by-default.sh: info: can not modify /etc/nginx/conf.d/default.conf (read-only file system?)
proxy_1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
proxy_1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
proxy_1 | /docker-entrypoint.sh: Configuration complete; ready for start up
mygoattheend-copy_app_1 exited with code 1
proxy_1 | 2022/11/03 18:51:39 [emerg] 1#1: host not found in upstream "app" in /etc/nginx/conf.d/default.conf:9
proxy_1 | nginx: [emerg] host not found in upstream "app" in /etc/nginx/conf.d/default.conf:9
mygoattheend-copy_proxy_1 exited with code 1
Other examples of errors that appear when i search for nginx: [emerg] host not found in upstream "app" in /etc/nginx/conf.d/default.conf:9 online suggest the problem is due to missing -depends_on: so ive included my docker-compose file below but i followed the tutorial perfectly and his worked fine. And my docker-compose-deploy has its
-depends_on:
my full docker compose is below
version: '3.7'
services:
app:
build:
context: .
ports:
- "8000:8000"
volumes:
- ./app:/app
command: sh -c "python manage.py runserver 0.0.0.0:8000"
environment:
- DEBUG=1
My full docker-compose-deploy.yml is below
version: '3.7'
services:
app:
build:
context: .
volumes:
- static_data:/vol/web
environment:
- SECRET_KEY=samplesecretkey123
- ALLOWED_HOSTS=127.0.0.1,localhost
proxy:
build:
context: ./proxy
volumes:
- static_data:/vol/static
ports:
- "8080:8080"
depends_on:
- app
volumes:
static_data:
the image below is my full directory
The error does mention that it can't find app, which i copy with the main dockerfile (not the one in the proxy folder)
My main dockerfile is below.
FROM python:3.8-alpine
ENV PATH="/scripts:${PATH}"
COPY ./requirements.txt /requirements.txt
RUN apk add --update --no-cache --virtual .tmp gcc libc-dev linux-headers
RUN pip install -r /requirements.txt
RUN apk del .tmp
RUN mkdir /app
COPY ./app /app
WORKDIR /app
COPY ./scripts /scripts
RUN chmod +x /scripts/*
RUN mkdir -p /vol/web/media
RUN mkdir -p /vol/web/
RUN adduser -D user
RUN chown -R user:user /vol
RUN chmod -R 755 /vol/web
USER user
CMD ["entrypoint.sh"]
what could be causing this error?
what other info do you need to work it out?
im following this tutorial. im at the very end https://www.youtube.com/watch?v=nh1ynJGJuT8
update 1 (adding extra info)
my proxy/default.conf is below
server {
listen 8080;
location /static {
alias /vol/static;
}
location / {
uwsgi_pass app:8000;
include /etc/nginx/uwsgi_params;
}
}
my proxy/dockerfile is below
FROM nginxinc/nginx-unprivileged:1-alpine
COPY ./default.conf /etc/nginx/conf.d/default.conf
COPY ./uwsgi_params /etc/nginx/uwsgi_params
USER root
RUN mkdir -p /vol/static
RUN chmod 755 /vol/static
USER nginx
update 2
this is my whole project uploaded to github https://github.com/tgmjack/help
update 3
editing the line endings in vscode didnt appear to work.
update 4
new dockerfile trying dos2unix
FROM python:3.8-alpine
ENV PATH="/scripts:${PATH}"
COPY ./requirements.txt /requirements.txt
RUN apk add --update --no-cache --virtual .tmp gcc libc-dev linux-headers dos2unix
RUN pip install -r /requirements.txt
RUN apk del .tmp
RUN mkdir /app
COPY ./app /app
WORKDIR /app
COPY ./scripts /scripts
RUN chmod +x /scripts/*
RUN mkdir -p /vol/web/media
RUN mkdir -p /vol/web/
RUN adduser -D user
RUN chown -R user:user /vol
RUN chmod -R 755 /vol/web
USER user
CMD ["dos2unix", "entrypoint.sh"]
but i still get the same error.
update 5
ok so i changed the eol of entrypoint.sh manually with notepad++ but i still get the same error.
do i need to apply this to more than just entrypoint.sh?

There are two problems in this setup.
DOS line endings
The first problem is the use of DOS line endings on the entrypoint. Here's what I see when I use od to get a character-by-character dump of the files:
$ od -c scripts/entrypoint.sh | head -n 2
0000000 # ! / b i n / s h \r \n \r \n s e t
0000020 - e \r \n \r \n p y t h o n m a
The issue is that after #!/bin/sh, we have \r\n, when we should have just \n. This is a DOS-style line ending, but Linux expects just a \n. More information
I used a program called dos2unix to replace those lines:
$ dos2unix scripts/entrypoint.sh
dos2unix: converting file scripts/entrypoint.sh to Unix format...
(VS code can do this too - here's how.)
When I run it, I get a new error:
app_1 | Traceback (most recent call last):
app_1 | File "manage.py", line 21, in <module>
app_1 | main()
app_1 | File "manage.py", line 17, in main
app_1 | execute_from_command_line(sys.argv)
app_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
app_1 | utility.execute()
app_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 345, in execute
app_1 | settings.INSTALLED_APPS
app_1 | File "/usr/local/lib/python3.8/site-packages/django/conf/__init__.py", line 76, in __getattr__
app_1 | self._setup(name)
app_1 | File "/usr/local/lib/python3.8/site-packages/django/conf/__init__.py", line 63, in _setup
app_1 | self._wrapped = Settings(settings_module)
app_1 | File "/usr/local/lib/python3.8/site-packages/django/conf/__init__.py", line 142, in __init__
app_1 | mod = importlib.import_module(self.SETTINGS_MODULE)
app_1 | File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
app_1 | return _bootstrap._gcd_import(name[level:], package, level)
app_1 | File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
app_1 | File "<frozen importlib._bootstrap>", line 991, in _find_and_load
app_1 | File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
app_1 | File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
app_1 | File "<frozen importlib._bootstrap_external>", line 843, in exec_module
app_1 | File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
app_1 | File "/app/app/settings.py", line 31, in <module>
app_1 | ALLOWED_HOSTS.extend(ALLOWED_HOSTS.split(',')) # .split(",") = incase multiple so we seperate them with a comma
app_1 | AttributeError: 'list' object has no attribute 'split'
Wrong variable referenced in settings file
I edited the file app/app/settings.py, and changed this line
ALLOWED_HOSTS.extend(ALLOWED_HOSTS.split(','))
to
ALLOWED_HOSTS.extend(ALLOWED_HOSTS_ENV.split(','))
After this, I found this worked.
Nginx
The nginx configuration turned out to be fine. The issue was that the app died, so nginx couldn't do a DNS lookup to find the IP address of the app container. Fixing the app container also fixes nginx.

Related

Trac MariaDB: AttributeError: 'NoneType' object has no attribute 'encoding'

I am trying to run trac on one container and install MariaDB on another container, on the trac container when I am trying to initialize the environment using trac-admin /path/to/env initenv I am getting the following error during specifying the database connection string which is running on another container:
Database connection string [sqlite:db/trac.db]> mysql://root:password#X.X.X.X:3306/trac
Initenv for '/usr/local/trac1' failed.
Failed to create environment.
'NoneType' object has no attribute 'encoding'
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/trac/admin/console.py", line 431, in do_initenv
options=options)
File "/usr/local/lib/python2.7/dist-packages/trac/core.py", line 141, in __call__
self.__init__(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/trac/env.py", line 259, in __init__
self.create(options)
File "/usr/local/lib/python2.7/dist-packages/trac/env.py", line 566, in create
DatabaseManager(self).init_db()
File "/usr/local/lib/python2.7/dist-packages/trac/db/api.py", line 285, in init_db
connector.init_db(**args)
File "/usr/local/lib/python2.7/dist-packages/trac/db/mysql_backend.py", line 133, in init_db
params)
File "/usr/local/lib/python2.7/dist-packages/trac/db/mysql_backend.py", line 118, in get_connection
cnx = MySQLConnection(path, log, user, password, host, port, params)
File "/usr/local/lib/python2.7/dist-packages/trac/db/mysql_backend.py", line 413, in __init__
host=host, port=port, **opts)
File "/usr/local/lib/python2.7/dist-packages/pymysql/__init__.py", line 94, in Connect
return Connection(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 285, in __init__
self.encoding = charset_by_name(self.charset).encoding
AttributeError: 'NoneType' object has no attribute 'encoding'
Created and granted permissions to the trac database using the following commands:
MariaDB [(none)]> CREATE DATABASE trac DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
Query OK, 1 row affected (0.007 sec)
MariaDB [(none)]> GRANT ALL ON trac.* TO root#X.X.X.X IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.026 sec)
Dockerfile for trac:
# This is a Dockerfile for trac
FROM quay.io/official-images/debian:bullseye-slim
LABEL description="Custom httpd container image for running trac"
RUN apt-get update \
&& apt-get install -y aptitude vim git wget gcc apache2 python2 python2-dev unzip
RUN apt-get install -y default-libmysqlclient-dev
RUN wget https://bootstrap.pypa.io/pip/2.7/get-pip.py \
&& python2 get-pip.py
RUN python2 -m pip install setuptools Jinja2 babel Pygments docutils pytz textile PyMySQL trac
EXPOSE 80 8000
ENV LogLevel "info"
ADD index.html /var/www/html
#RUN trac-admin /usr/local/trac initenv trac mysql://root:user#X.X.X.X:3306/trac
#RUN tracd --port 8000 /usr/local/trac &
ENTRYPOINT ["apachectl"]
CMD ["-D", "FOREGROUND"]
Dockerfile for MariaDB:
# This is a Dockerfile for MariaDB to be used with trac
FROM docker.io/mariadb:latest
LABEL description="Custom mariadb container image for running trac"
ARG MARIADB_USER=db_user
ARG MARIADB_ROOT_PASSWORD=db_pw
ARG MARIADB_DATABASE=db_name
ENV PACKAGES openssh-server openssh-client
ENV MARIADB_USER $MARIADB_USER
ENV MARIADB_ROOT_PASSWORD $MARIADB_ROOT_PASSWORD
ENV MARIADB_DATABASE $MARIADB_DATABASE
RUN mkdir /db_backup
ADD trac.sql /db_backup
RUN apt-get update && apt-get install -y $PACKAGES
EXPOSE 3306
CMD ["mysqld"]
I figured it out myself, while I was trying to create the database using the command specified in the trac documentation (mentioned in the question) I was getting the following character_set_database and collation_database:
MariaDB [trac]> SHOW VARIABLES WHERE variable_name IN ('character_set_database', 'collation_database');
+------------------------+-------------+
| Variable_name | Value |
+------------------------+-------------+
| character_set_database | utf8mb3 |
| collation_database | utf8mb3_bin |
+------------------------+-------------+
The following command should be used to create the database with the correct encodings:
MariaDB [(none)]> CREATE DATABASE trac CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_bin;
Query OK, 1 row affected (0.001 sec)
Results:
MariaDB [(none)]> use trac
Database changed
MariaDB [trac]> SHOW VARIABLES WHERE variable_name IN ('character_set_database', 'collation_database');
+------------------------+-------------+
| Variable_name | Value |
+------------------------+-------------+
| character_set_database | utf8mb4 |
| collation_database | utf8mb4_bin |
+------------------------+-------------+
2 rows in set (0.003 sec)

why docker does not recognize /bin/sh -c as a valid entrypoint?

I have a simple nginx container trying to run from docker-compose..
version: "3.3"
services:
nginx:
image: nginx
privileged: true
entrypoint: ["/bin/sh -c"]
command: ["ls -lha ~"]
but it fails with:
docker-compose up -d
ERROR: for junk_nginx_1 Cannot start service nginx: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "/bin/sh -c": stat /bin/sh -c: no such file or directory: unknown
I thought it was because /bin/sh doesn't exists in the image, but it certainly does. removing the -c gives me the following error:
# this time the container runs, this is in the container logs.
/bin/sh: 0: Can't open ls -lha ~
so /bin/sh does exists within the image. what am I doing wrong?
When you use the array form of Compose command: and entrypoint: (and, similarly, the JSON-array form of Dockerfile CMD, ENTRYPOINT, and RUN), you are responsible for breaking up the input into words. Each item in the array is a word, just as though it was quoted in the shell, and includes any spaces, punctuation, and other characters.
So when you say
entrypoint: ["/bin/sh -c"]
That is one word, not a command and its argument, and you are telling the shell to look for an executable program named sh -c (including space hyphen c as part of the filename) in the /bin directory. Since that's not there, you get an error.
You shouldn't usually need to override entrypoint: in a Compose setup. In your case, the only shell expansion you need is the home directory ~ but that's not well-defined in Docker. You should be able to just write
command: ls -lha /usr/share/nginx/html
or in array form
command: ["ls", "-lha", "/usr/share/nginx/html"]
# (or other YAML syntaxes with fewer quotes or more lines)
or if you really need the sh -c wrapper
command: /bin/sh -c 'ls -lha ~'
command: ["/bin/sh", "-c", "ls -lha ~"]
command:
- /bin/sh
- -c
- >-
ls -lha ~;
echo these lines get folded together;
nginx -g 'daemon off;'
You're using the stock Docker Hub nginx image; also consider whether docker-compose run might be an easier way to run a one-off command
docker-compose run nginx \
ls -lha /usr/share/nginx/html
If it's your own image, try hard to avoid needing to override ENTRYPOINT. Make CMD be a complete command; if you need an ENTRYPOINT, a shell script that ends with exec "$#" so that it runs the CMD is a typical pattern.
See entrypoint usage:
entrypoint: ["php", "-d", "memory_limit=-1", "vendor/bin/phpunit"]
Also see command usage:
command: ["bundle", "exec", "thin", "-p", "3000"]
So, your error means your syntax not ok, the correct one for you is:
version: "3.3"
services:
nginx:
image: nginx
privileged: true
entrypoint: ["/bin/sh", "-c"]
command: ["ls", "-lha", "~"]
The execution:
$ docker-compose up
Creating network "20210812_default" with the default driver
Creating 20210812_nginx_1 ... done
Attaching to 20210812_nginx_1
nginx_1 | bin
nginx_1 | boot
nginx_1 | dev
nginx_1 | docker-entrypoint.d
nginx_1 | docker-entrypoint.sh
nginx_1 | etc
nginx_1 | home
nginx_1 | lib
nginx_1 | lib64
nginx_1 | media
nginx_1 | mnt
nginx_1 | opt
nginx_1 | proc
nginx_1 | root
nginx_1 | run
nginx_1 | sbin
nginx_1 | srv
nginx_1 | sys
nginx_1 | tmp
nginx_1 | usr
nginx_1 | var
20210812_nginx_1 exited with code 0

Unable to connect Mlflow server to my mlflow project image

My final purpose is to run experiment from an Api.
the experiment come from :
https://github.com/mlflow/mlflow/tree/master/examples/tensorflow/tf2
but export the file in my custom git where I clone it, in the image below ->
I have 2 images in my docker compose :
tree project :
|_app/
| |_Dockerfile
|
|_mlflow/
| |_Dockerfile
|
|_docker-compose.yml
app/Dockerfile
FROM continuumio/anaconda3
ENV APP_HOME ./
WORKDIR ${APP_HOME}
RUN conda config --append channels conda-forge
RUN conda install --quiet --yes \
'mlflow' \
'psycopg2' \
'tensorflow'
RUN pip install pylint
RUN pwd;ls \
&& git clone https://github.com/MChrys/QuickSign.git
RUN pwd;ls \
&& cd QuickSign \
&& pwd;ls
COPY . .
#RUN conda install jupyter
#CMD jupyter notebook --ip=0.0.0.0 --port=8888 --allow-root --no-browser
CMD cd QuickSign && mlflow run .
mlflow/Dockerfile
FROM python:3.7.0
RUN pip install mlflow
RUN mkdir /mlflow/
CMD mlflow server \
--backend-store-uri /mlflow \
--host 0.0.0.0
docker-compose.yml
version: '3'
services:
notebook:
build:
context: ./app
ports:
- "8888:8888"
depends_on:
- mlflow
environment:
MLFLOW_TRACKING_URI: 'http://mlflow:5000'
mlflow:
build:
context: ./mlflow
expose:
- "5000"
ports:
- "5000:5000"
when I docker-compose up the image I obtain :
notebook_1_74059cdc20ce | response = requests.request(**kwargs)
notebook_1_74059cdc20ce | File "/opt/conda/lib/python3.7/site-packages/requests/api.py", line 60, in request
notebook_1_74059cdc20ce | return session.request(method=method, url=url, **kwargs)
notebook_1_74059cdc20ce | File "/opt/conda/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
notebook_1_74059cdc20ce | resp = self.send(prep, **send_kwargs)
notebook_1_74059cdc20ce | File "/opt/conda/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
notebook_1_74059cdc20ce | r = adapter.send(request, **kwargs)
notebook_1_74059cdc20ce | File "/opt/conda/lib/python3.7/site-packages/requests/adapters.py", line 516, in send
notebook_1_74059cdc20ce | raise ConnectionError(e, request=request)
notebook_1_74059cdc20ce | requests.exceptions.ConnectionError: HTTPConnectionPool(host='mlflow', port=5000): Max retries exceeded with url: /api/2.0/mlflow/runs/create (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fd5db4edc50>: Failed to establish a new connection: [Errno 111] Connection refused'))
The problem look like that I run a project which is not found in the server images, as I run it in the app image, but I don't know how figure it out I have to trigger the experiment from a futur flask app
It looks like the server is not reachable from the app. I assume docker-compose.yml is used by the project running in the app, so that is trying to contact the mlflow server at MLFLOW_TRACKING_URI: 'http://mlflow:5000'. Is http://mlflow:5000 a domain you have set up? Where is it supposed to be reachable from?
The problem came from docker for windows, I was unable to make working docker compose on it but there are no problem to build it when I run it on virtual machine with ubuntu.

how to run chromedp in docker

I am trying to run chromedp in docker.
My main.go:
package main
import (
"context"
"log"
"time"
"github.com/chromedp/chromedp"
)
func main() {
log.SetFlags(log.LstdFlags | log.Llongfile)
ctx, cancel := chromedp.NewContext(
context.Background(),
chromedp.WithLogf(log.Printf),
)
defer cancel()
// create a timeout
ctx, cancel = context.WithTimeout(ctx, 15 * time.Second)
defer cancel()
u := `https://www.whatismybrowser.com/detect/what-is-my-user-agent`
selector := `#detected_value`
log.Println("requesting", u)
log.Println("selector", selector)
var result string
err := chromedp.Run(ctx,
chromedp.Navigate(u),
chromedp.WaitReady(selector),
chromedp.OuterHTML(selector, &result),
)
if err != nil {
log.Fatal(err)
}
log.Printf("result:\n%s", result)
}
Dockerfile:
FROM golang:latest as build-env
RUN mkdir $GOPATH/src/app
WORKDIR $GOPATH/src/app
ENV GO111MODULE=on
COPY go.mod .
COPY go.sum .
COPY main.go .
RUN go mod download
RUN go build -o /root/app
FROM chromedp/headless-shell
COPY --from=build-env /root/app /
CMD ["/app"]
When I run it:
docker-compose build
docker-compose up
It outputs:
app_1 | [1129/192523.576726:WARNING:resource_bundle.cc(426)] locale_file_path.empty() for locale
app_1 | [1129/192523.602779:WARNING:resource_bundle.cc(426)] locale_file_path.empty() for locale
app_1 |
app_1 | DevTools listening on ws://0.0.0.0:9222/devtools/browser/3fa247e0-e2fa-484e-8b5f-172b392701bb
app_1 | [1129/192523.836854:WARNING:resource_bundle.cc(426)] locale_file_path.empty() for locale
app_1 | [1129/192523.838804:WARNING:resource_bundle.cc(426)] locale_file_path.empty() for locale
app_1 | [1129/192523.845866:ERROR:egl_util.cc(60)] Failed to load GLES library: /headless-shell/swiftshader/libGLESv2.so: /headless-shell/swiftshader/libGLESv2.so: cannot open shared object file: No such file or directory
app_1 | [1129/192523.871796:ERROR:viz_main_impl.cc(176)] Exiting GPU process due to errors during initialization
app_1 | [1129/192523.897083:WARNING:gpu_process_host.cc(1220)] The GPU process has crashed 1 time(s)
app_1 | [1129/192523.926741:WARNING:resource_bundle.cc(426)] locale_file_path.empty() for locale
app_1 | [1129/192523.930111:ERROR:egl_util.cc(60)] Failed to load GLES library: /headless-shell/swiftshader/libGLESv2.so: /headless-shell/swiftshader/libGLESv2.so: cannot open shared object file: No such file or directory
app_1 | [1129/192523.943794:ERROR:viz_main_impl.cc(176)] Exiting GPU process due to errors during initialization
app_1 | [1129/192523.948757:WARNING:gpu_process_host.cc(1220)] The GPU process has crashed 2 time(s)
app_1 | [1129/192523.950107:ERROR:browser_gpu_channel_host_factory.cc(138)] Failed to launch GPU process.
app_1 | [1129/192524.013014:ERROR:browser_gpu_channel_host_factory.cc(138)] Failed to launch GPU process.
So it doesn't run my go app. I expect that chromedp/headless-shell contains google-chrome and my golang app would successfully use it over github.com/chromedp/chromedp
Update 1
I added missing directories:
RUN mkdir -p /headless-shell/swiftshader/ \
&& cd /headless-shell/swiftshader/ \
&& ln -s ../libEGL.so libEGL.so \
&& ln -s ../libGLESv2.so libGLESv2.so
and now have the following output, my app still not running:
app_1 | [1202/071210.095414:WARNING:resource_bundle.cc(426)] locale_file_path.empty() for locale
app_1 | [1202/071210.112632:WARNING:resource_bundle.cc(426)] locale_file_path.empty() for locale
app_1 |
app_1 | DevTools listening on ws://0.0.0.0:9222/devtools/browser/86e31db1-3a17-4da6-9e2f-696647572492
app_1 | [1202/071210.166158:WARNING:resource_bundle.cc(426)] locale_file_path.empty() for locale
app_1 | [1202/071210.186307:WARNING:resource_bundle.cc(426)] locale_file_path.empty() for locale
Update 2
Looks like CMD ["/app"] doesn't run my main.go file because it doesn't print any lines from it.
And when I run it manually:
$ /usr/local/bin/docker exec -ti chromedp_docker_app_1 /bin/bash
root#0c417fd159a2:/# /app
2019/12/02 07:40:34 app is running
2019/12/02 07:40:34 /go/src/app/main.go:26: requesting https://www.whatismybrowser.com/detect/what-is-my-user-agent
2019/12/02 07:40:34 /go/src/app/main.go:27: selector #detected_value
2019/12/02 07:40:34 /go/src/app/main.go:35: exec: "google-chrome": executable file not found in $PATH
I see that google-chrome app is still not there, hmmm....
You are missing few things here, First you need to run google-headless-chrome inside your container. you can use following Dockerfile
FROM golang:1.12.0-alpine3.9
RUN apk update && apk upgrade && apk add --no-cache bash git && apk add --no-cache chromium
# Installs latest Chromium package.
RUN echo #edge http://nl.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories \
&& echo #edge http://nl.alpinelinux.org/alpine/edge/main >> /etc/apk/repositories \
&& apk add --no-cache \
harfbuzz#edge \
nss#edge \
freetype#edge \
ttf-freefont#edge \
&& rm -rf /var/cache/* \
&& mkdir /var/cache/apk
RUN go get github.com/mafredri/cdp
CMD chromium-browser --headless --disable-gpu --remote-debugging-port=9222 --disable-web-security --safebrowsing-disable-auto-update --disable-sync --disable-default-apps --hide-scrollbars --metrics-recording-only --mute-audio --no-first-run --no-sandbox
I am using CDP, More robust and fun for me!
This is the link for CDP: https://github.com/mafredri/cdp
Is not pretty but here is a simple docker that worked for me
FROM golang:1.16.5 AS build-env
RUN apt update && apt -y upgrade
RUN apt -y install chromium
WORKDIR /app
ADD ./ ./
RUN go mod download
RUN go build -o /docker-gs-ping
CMD [ "/docker-gs-ping" ]

"OSError: [Errno 8] Exec format error" when trying to run simple flask app in a docker container

I'm trying to start a simple Flask "Hello world" app in a docker container but I keep getting this error: "OSError: [Errno 8] Exec format error: '/app/app.py'"
My host operating system is Windows 10.
My Dockerfile:
FROM python:3.6
ENV PYTHONBUFFERED 1
ADD . /app
WORKDIR /app
RUN pip install -r requirements.txt
I have requirements.txt with Flask==1.0.2.
app.py:
from flask import Flask
app = Flask(__name__)
#app.route("/")
def hello():
return "Hello World!"
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000, debug=True)
and docker-compose.yml:
version: '3'
services:
app:
build: .
command: python app.py
ports:
- "8000:8000"
Whole log of container:
app_1 | * Serving Flask app "app" (lazy loading)
app_1 | * Environment: production
app_1 | WARNING: Do not use the development server in a production environment.
app_1 | Use a production WSGI server instead.
app_1 | * Debug mode: on
app_1 | * Running on http://0.0.0.0:8000/ (Press CTRL+C to quit)
app_1 | * Restarting with stat
app_1 | Traceback (most recent call last):
app_1 | File "app.py", line 9, in <module>
app_1 | app.run(host='0.0.0.0', port=8000, debug=True)
app_1 | File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 943, in run
app_1 | run_simple(host, port, self, **options)
app_1 | File "/usr/local/lib/python3.6/site-packages/werkzeug/serving.py", line 988, in run_simple
app_1 | run_with_reloader(inner, extra_files, reloader_interval, reloader_type)
app_1 | File "/usr/local/lib/python3.6/site-packages/werkzeug/_reloader.py", line 332, in run_with_reloader
app_1 | sys.exit(reloader.restart_with_reloader())
app_1 | File "/usr/local/lib/python3.6/site-packages/werkzeug/_reloader.py", line 176, in restart_with_reloader
app_1 | exit_code = subprocess.call(args, env=new_environ, close_fds=False)
app_1 | File "/usr/local/lib/python3.6/subprocess.py", line 287, in call
app_1 | with Popen(*popenargs, **kwargs) as p:
app_1 | File "/usr/local/lib/python3.6/subprocess.py", line 729, in __init__
app_1 | restore_signals, start_new_session)
app_1 | File "/usr/local/lib/python3.6/subprocess.py", line 1364, in _execute_child
app_1 | raise child_exception_type(errno_num, err_msg, err_filename)
app_1 | OSError: [Errno 8] Exec format error: '/app/app.py'
flaskdockerproject_app_1 exited with code 1
UPDATE
After I added the shebang in app.py like #larsks said I'm getting this error:
"FileNotFoundError: [Errno 2] No such file or directory: '/app/app.py': '/app/app.py'.
All the files are in the container and in the right place.
I hit the same problem (Exec format error, then FileNotFound if I added the shebang).
Adding "RUN chmod 644 app.py" to the Dockerfile fixed it for me, as mentioned here: https://github.com/pallets/werkzeug/issues/1482
Spent the entire day yesterday putting the pieces together on this problem, forum by forum, so I want to share a more detailed answer to this question. While building my image, I was also seeing the following warning message:
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host.
"That warning was added, because the Windows filesystem does not have an option to mark a file as 'executable'. Building a linux image from a Windows machine would therefore break the image if a file has to be marked executable." - https://github.com/moby/moby/issues/20397
So, as Richard Chamberlain points out in the comment above, adding "RUN chmod 644.py" ensures that the app.py file is properly marked.
Putting all the pieces together, here is the complete Dockerfile that worked for me - Really hope it helps the next person struggling with this issue!
FROM python:3.7-alpine
COPY . /app
WORKDIR /app
RUN apk add --no-cache --virtual .build-deps \
ca-certificates gcc postgresql-dev linux-headers musl-dev \
libffi-dev jpeg-dev zlib-dev \
&& pip install --no-cache -r requirements.txt
RUN chmod 644 app.py
CMD ["python","app.py"]

Resources