Failing to build docker container on remote host - docker

I have a set of docker containers that are generated from yml files and work ok.
I now want to deploy them to another machine. In another post here I was advised to build the container on the remote host using one of 2 options:
option1 - copy the code to the remote host and apply a modified docker-compose, and build from source using a modified docker-compose
option2 - create an image on local machine, push it to a docker repository, pull it from there, using a modified docker-compose
I'm trying to follow option1 (as a start). I copied the code into the remote host, and modified the Dockerfile, and docker-compose.yml files (snippet1)
The build goes partway through. It downloads the python and postgres images, and starts to process the Dockerfile, but it fails to install the requirements (it fails to install the first requirement - see snippet2)
What can be the problem?
snippet1 - Dockerfile.dair, and docker-compose.yml
cat /home/ubuntu/webServer/web/Dockerfile.dair
FROM python:3.6.1
MAINTAINER User4 <user4#gmail.com>
# Create the group and user to be used in this container
RUN groupadd flaskgroup && useradd -m -g flaskgroup -s /bin/bash flask
# Create the working directory (and set it as the working directory)
RUN mkdir -p /home/flask/app/web
WORKDIR /home/flask/app/web
# Install the package dependencies (this step is separated
# from copying all the source code to avoid having to
# re-install all python packages defined in requirements2.txt
# whenever any source code change is made)
COPY requirements2.txt /home/flask/app/web
RUN pip install --no-cache-dir -r requirements2.txt
# Copy the source code into the container
COPY . /home/flask/app/web
RUN chown -R flask:flaskgroup /home/flask
USER flask
EXPOSE 8000
CMD /usr/local/bin/gunicorn -w 2 -t 3600 -b :8000 project:app
ENV PYTHONUNBUFFERED=1
ENV FLASK_APP=run.py
ENV FLASK_DEBUG=1
,
cat /home/ubuntu/construction_overlay/webServer/docker-compose.dair.yml
version: '3'
services:
web:
restart: always
build:
context: ./web
dockerfile: Dockerfile.dair
volumes:
- /home/ubuntu/construction_overlay/webServer/web:/home/flask/app/web
depends_on:
- postgres
nginx:
restart: always
build: ./nginx
ports:
- "80:80"
volumes:
- /home/ubuntu/construction_overlay/webServer/web:/home/flask/app/web
depends_on:
- web
postgres:
restart: always
build: ./postgresql
volumes:
- data1:/var/lib/postgresql
expose:
- "5432"
volumes:
data1:
snippet2 - the build fails to install the requirements
cat /home/ubuntu/webServer/web/requirements.txt
alembic==0.8.8
atomicwrites==1.3.0
attrs==19.1.0
...
,
docker-compose -f /home/ubuntu/webServer/docker-compose.dair.yml up --build -d;
Building postgres
Step 1/4 : FROM postgres:11.3
---> 4e045cb8eecd
Step 2/4 : ENV POSTGRES_USER postgres_user
---> Using cache
---> 400023c58607
Step 3/4 : ENV POSTGRES_PASSWORD postgres_user
---> Using cache
---> 0cf91f314380
Step 4/4 : ENV POSTGRES_DB construction-overlay-db
---> Using cache
---> 151106ecf13b
Successfully built 151106ecf13b
Successfully tagged webserver_postgres:latest
Building web
Step 1/10 : FROM python:3.6.1
---> 955d0c3b1bb2
Step 2/10 : MAINTAINER User4 <user4#gmail.com>
---> Using cache
---> 128d55ddb4e7
Step 3/10 : RUN groupadd flaskgroup && useradd -m -g flaskgroup -s /bin/bash flask
---> Using cache
---> e2c30915fcf5
Step 4/10 : RUN mkdir -p /home/flask/app/web
---> Using cache
---> 8f44dada5953
Step 5/10 : WORKDIR /home/flask/app/web
---> Using cache
---> 04a895c3fe27
Step 6/10 : COPY requirements.txt /home/flask/app/web
---> Using cache
---> 13ab37e789f8
Step 7/10 : RUN pip install --no-cache-dir -r requirements.txt
---> Running in 61475950cd73
Collecting alembic==0.8.8 (from -r requirements.txt (line 1))
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f1e979262b0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/alembic/

The solution was to add a rule for UDP outbound at the cloud provider
After adding this rule, the pre-requirements install ok
Egress IPv4 UDP 1 - 65535 0.0.0.0/0

Related

executable not found on docker container

I'm having some issue trying to run a CMD command inside a docker container with a Go application.
This is the output I've got:
golang-api | /bin/sh: ./server: not found
golang-api exited with code 127
This is the Dockerfile
FROM golang:1.18-alpine
RUN apk add g++ && apk add make
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN make build
EXPOSE 8000
CMD ./server
And this is the Makefile responsible for the build command:
LINUX_AMD64 = GOOS=linux GOARCH=amd64 CGO_ENABLED=1 GO111MODULE=on
migrate:
cd cmd/migrations/$(FOLDER) && go run main.go
build:
cd cmd && $(LINUX_AMD64) go build -a -v -tags musl -o server
And the docker-compose.yml
version: '3.1'
services:
api:
build:
dockerfile: Dockerfile
context: .
container_name: golang-api
ports:
- "8000:8000"
restart: unless-stopped
depends_on:
- db
environment:
- POSTGRES_URL=$POSTGRES_URL
db:
image: postgres
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- '5432:5432'
Complete output:
Building api
Sending build context to Docker daemon 74.24kB
Step 1/9 : FROM golang:1.18-alpine
---> 6078a5fce1f5
Step 2/9 : RUN apk add g++ && apk add make
---> Using cache
---> 2a85b9182b80
Step 3/9 : WORKDIR /app
---> Using cache
---> baf1e6b7047c
Step 4/9 : COPY go.mod go.sum ./
---> Using cache
---> 1f2d031bc1b0
Step 5/9 : RUN go mod download
---> Using cache
---> 471d6f24e6a9
Step 6/9 : COPY . .
---> eaa86ff7cb1b
Step 7/9 : RUN make build
---> Running in d6ae6ce79222
cd cmd && GOOS=linux GOARCH=amd64 CGO_ENABLED=1 GO111MODULE=on go build -a -v -tags musl -o server
internal/goos
internal/goarch
internal/race
internal/unsafeheader
internal/goexperiment
runtime/internal/syscall
internal/cpu
sync/atomic
runtime/internal/atomic
internal/itoa
math/bits
internal/abi
runtime/internal/math
runtime/internal/sys
unicode/utf8
unicode
container/list
crypto/internal/subtle
crypto/subtle
unicode/utf16
vendor/golang.org/x/crypto/cryptobyte/asn1
internal/nettrace
vendor/golang.org/x/crypto/internal/subtle
encoding
github.com/mymachine/my-api/internal/controllers/dto
github.com/mymachine/my-api/internal/controllers/helpers
internal/bytealg
math
runtime
internal/reflectlite
sync
internal/testlog
internal/singleflight
math/rand
runtime/cgo
errors
sort
internal/oserror
strconv
path
vendor/golang.org/x/net/dns/dnsmessage
io
crypto/elliptic/internal/fiat
syscall
golang.org/x/text/internal/tag
hash
bytes
strings
hash/crc32
reflect
crypto
crypto/internal/randutil
crypto/hmac
crypto/rc4
net/http/internal/ascii
vendor/golang.org/x/crypto/hkdf
regexp/syntax
github.com/jackc/chunkreader/v2
bufio
crypto/elliptic/internal/nistec
internal/syscall/unix
time
internal/syscall/execenv
vendor/golang.org/x/text/transform
golang.org/x/crypto/pbkdf2
golang.org/x/text/transform
golang.org/x/text/runes
golang.org/x/text/width
regexp
internal/poll
io/fs
context
github.com/mymachine/my-api/internal/entities
github.com/jackc/pgconn/internal/ctxwatch
embed
os
github.com/jinzhu/inflection
github.com/jinzhu/now
internal/fmtsort
encoding/binary
crypto/ed25519/internal/edwards25519/field
crypto/md5
crypto/sha512
crypto/cipher
crypto/sha256
crypto/sha1
encoding/base64
fmt
internal/godebug
encoding/pem
crypto/ed25519/internal/edwards25519
path/filepath
vendor/golang.org/x/crypto/internal/poly1305
io/ioutil
internal/intern
vendor/golang.org/x/crypto/curve25519/internal/field
vendor/golang.org/x/sys/cpu
net/netip
crypto/aes
crypto/des
vendor/golang.org/x/crypto/chacha20
github.com/jackc/pgio
github.com/jackc/pgpassfile
os/exec
os/signal
net
vendor/golang.org/x/crypto/chacha20poly1305
math/big
encoding/hex
net/url
compress/flate
vendor/golang.org/x/crypto/curve25519
log
vendor/golang.org/x/text/unicode/norm
vendor/golang.org/x/text/unicode/bidi
vendor/golang.org/x/net/http2/hpack
mime
mime/quotedprintable
compress/gzip
net/http/internal
database/sql/driver
github.com/mymachine/my-api/internal/pkg/errors
encoding/json
github.com/jackc/pgservicefile
vendor/golang.org/x/text/secure/bidirule
golang.org/x/text/internal/language
database/sql
golang.org/x/text/unicode/norm
golang.org/x/text/unicode/bidi
vendor/golang.org/x/net/idna
os/user
crypto/rand
encoding/asn1
crypto/dsa
crypto/elliptic
crypto/ed25519
crypto/rsa
github.com/jackc/pgproto3/v2
golang.org/x/text/internal/language/compact
golang.org/x/text/secure/bidirule
github.com/jackc/pgx/v4/internal/sanitize
golang.org/x/text/language
go/token
vendor/golang.org/x/crypto/cryptobyte
crypto/x509/pkix
gorm.io/gorm/utils
gorm.io/gorm/logger
encoding/gob
go/scanner
golang.org/x/text/internal
github.com/joho/godotenv
crypto/ecdsa
go/ast
golang.org/x/text/cases
github.com/joho/godotenv/autoload
golang.org/x/text/secure/precis
gorm.io/gorm/clause
gorm.io/gorm/schema
gorm.io/gorm
net/textproto
vendor/golang.org/x/net/http/httpproxy
github.com/google/uuid
crypto/x509
github.com/jackc/pgtype
mime/multipart
vendor/golang.org/x/net/http/httpguts
crypto/tls
gorm.io/gorm/migrator
gorm.io/gorm/callbacks
net/http/httptrace
github.com/jackc/pgconn
net/http
github.com/jackc/pgconn/stmtcache
github.com/jackc/pgx/v4
github.com/jackc/pgx/v4/stdlib
gorm.io/driver/postgres
github.com/mymachine/my-api/internal/infrastructure/repository
github.com/mymachine/my-api/configs
github.com/mymachine/my-api/internal/services
github.com/mymachine/my-api/internal/services/transaction
github.com/mymachine/my-api/internal/controllers/handlers/health
github.com/gorilla/mux
github.com/mymachine/my-api/internal/controllers/handlers/transaction
github.com/mymachine/my-api/internal/router
github.com/mymachine/my-api/cmd
Removing intermediate container d6ae6ce79222
---> 621aa6a266de
Step 8/9 : EXPOSE 8000
---> Running in 3cbd17d32c37
Removing intermediate container 3cbd17d32c37
---> 754f71a7753e
Step 9/9 : CMD ./server
---> Running in dfcdc8cd45ce
Removing intermediate container dfcdc8cd45ce
---> 511dbf89a001
Successfully built 511dbf89a001
Successfully tagged my-api_api:latest
Creating my-api_db_1 ... done
Creating golang-api ... done
Attaching to my-api_db_1, golang-api
golang-api | /bin/sh: ./server: not found
The problem was solved.
Somehow,the RUN cd cmd command seemed not generating the file in the expected directory.
Trying with RUN go build cmd/main.go instead of using the makefile worked, as well pointed by #paltaa in the comments.

docker-compose.yml with entrypoint. file not found

Tried a lot already, but doesn't want to run docker-compose with entrypoint...
I'm new to docker and trying to figure it out, but I can't seem to run the program through entrypoint.sh
Dockerfile
FROM python:3.7-alpine
WORKDIR /app
RUN apk update && apk add postgresql-dev gcc python3-dev musl-dev
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
RUN /usr/local/bin/python3 -m pip install --upgrade pip
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY /web .
COPY entrypoint.sh entrypoint.sh
RUN chmod u+x ./entrypoint.sh
docker-compose.yml
version: "3.9"
services:
web:
build: .
ports:
- "5000:5000"
volumes:
- ./web:/app
environment:
PG_HOST: pg
PG_USER: ${POSTGRES_USER}
PG_PASSWORD: ${POSTGRES_PASSWORD}
PG_DB: ${POSTGRES_DB}
depends_on:
- pg
entrypoint: entrypoint.sh
pg:
image: "postgres:alpine"
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
# PGDATA: /var/lib/postgresql/data/pgdata
# volumes:
# - ./data/pgdata:/var/lib/postgresql/data/pgdata
ports:
- 5432:5432
entrypoint.sh
#python3 manage.py db upgrade
flask run --host=0.0.0.0
ERROR:
Step 1/11 : FROM python:3.7-alpine
---> c051b8594107
Step 2/11 : WORKDIR /app
---> Using cache
---> d19c508ff35c
Step 3/11 : RUN apk update && apk add postgresql-dev gcc python3-dev musl-dev
---> Using cache
---> 19b5e197621a
Step 4/11 : ENV FLASK_APP=app.py
---> Using cache
---> af02528555c4
Step 5/11 : ENV FLASK_RUN_HOST=0.0.0.0
---> Using cache
---> 4029b777d985
Step 6/11 : RUN /usr/local/bin/python3 -m pip install --upgrade pip
---> Using cache
---> e94f1f70106b
Step 7/11 : COPY requirements.txt requirements.txt
---> Using cache
---> fb4ad7239fa2
Step 8/11 : RUN pip install -r requirements.txt
---> Using cache
---> 1f912edd8219
Step 9/11 : COPY /web .
---> Using cache
---> 32966afa52ee
Step 10/11 : COPY entrypoint.sh entrypoint.sh
---> Using cache
---> 11525954905f
Step 11/11 : RUN chmod u+x ./entrypoint.sh
---> Using cache
---> 575c41093e1f
...
Successfully built 89b11d4d5f71
Successfully tagged rodauth_web:latest
rodauth_pg_1 is up-to-date
Recreating 1e4f3f2f6898_rodauth_web_1 ...
Recreating 1e4f3f2f6898_rodauth_web_1 ... error
ERROR: for 1e4f3f2f6898_rodauth_web_1 Cannot start service web: OCI runtime create failed: container_linux.go:370: starting container process caused: exec: "entrypoint.sh": executable file not found in $PATH: unknown
ERROR: for web Cannot start service web: OCI runtime create failed: container_linux.go:370: starting container process caused: exec: "entrypoint.sh": executable file not found in $PATH: unknown
Encountered errors while bringing up the project.
tried adding command RUN chmod u+x ./entrypoint.sh but
the problem is not gone.
Added the build log for COPY entrypoint.sh entrypoint.sh part.
Your entrypoint.sh file get removed from the container when you mount ./web to /app folder as a volume in docker-compose file. so copy entrypoint to root
COPY entrypoint.sh /entrypoint.sh
RUN chmod u+x /entrypoint.sh
And set entrypoint in docker-compose as
entrypoint: /entrypoint.sh
instead of COPY /web ., just do COPY . /app where you are copying the same structure into /app. as you mentioned, workdir /app you are already in that app folder.
or you can just change the last line, COPY entrypoint.sh .
simple docker example : https://github.com/cerofrais/baiscs/tree/master/basic_docker
First, if you want the script to be the normal entrypoint for the image, I'd move that into the Dockerfile with the following:
ENTRYPOINT ["./entrypoint.sh"]
As for why you'd see a file not found error on a script, several potential reasons:
The first line, e.g. #!/bin/bash, points to a command that does not exist in the image you are using. You need to update your script to use the right shell, or change base images to one that includes your shell.
The script is formatted with Windows linefeeds that include a CR before the LF. That turns /bin/sh into /bin/sh^M (sometimes shown as /bin/sh\r) which doesn't exist in the filesystem. This can be fixed by changing the line feed format in your editor, fixing Git to change how linefeeds are automatically changed, or using a tool like dos2unix.
If you run an image for a different platform, and have qemu binfmt_misc installed but without the --fix-binary option, it will look for the interpreter for your platform inside the image rather that from the host. Often this can be fixed with a newer version of binfmt_misc.
The exec format error mentioned in the comments indicates you are running an image designed for another platform on your host. Docker will attempt to pull the proper platform if you have a multi-platform image. However if the image is only built for one platform, and you try to run it on a different platform without something like qemu's binfmt_misc properly configured, you'll get errors. And the fix for that is to change base images to one that supports that CPU architecture and binary format where you are running the image.
This is how I customized Ravisha Hesh's answer and it worked for me.
COPY entrypoint.sh /entrypoint.sh
RUN chmod u+x /entrypoint.sh
CMD ["/entrypoint.sh"]

COPY command fails

Been stuck on this for the last 3 days. I'm building an image in a docker and
copy command fails due to not finding the right directory.
FROM python:3.6.7-alpine
WORKDIR /usr/src/app
COPY ./requirements.txt /usr/src/app/requirements.txt
RUN pip3 install -r requirements.txt
COPY . /usr/src/app
CMD python3 manage.py run -h 0.0.0.0
which is run by this docker-dev file:
version: '3.7'
services:
users:
build:
context: ./services/users
dockerfile: Dockerfile-dev
volumes:
- './services/users:/usr/src/app'
ports:
- 5001:5000
environment:
- FLASK_APP=project/__init__.py
- FLASK_ENV=development
and getting this error:
Building users
Step 1/6 : FROM python:3.6.7-alpine
---> cb04a359db13
Step 2/6 : WORKDIR /usr/src/app
---> Using cache
---> 06bb39a49444
Step 3/6 : COPY ./requirements.txt /usr/src/app/requirements.txt
ERROR: Service 'users' failed to build: COPY failed: stat /var/snap/docker/common/var-lib-docker/tmp/docker-builder353668631/requirements.txt: no such file or directory
I don't even know where to start with debugging this. When I tried to access the directory it gave me permission error. So I tried to run the command with sudo which didn't help. Any thoughts ?
Little late to reply, but second COPY command COPY . /usr/src/app replaces the /usr/src/app content generated by RUN pip3 install -r requirements.txt.
Try
FROM python:3.6.7-alpine
WORKDIR /usr/src/app
# install in temp directory
RUN mkdir /dependencies
COPY ./requirements.txt /dependencies/requirements.txt
RUN cd /dependencies && pip3 install -r requirements.txt
COPY . /usr/src/app
# copy generated dependencies
RUN cp -r /dependencies/* /usr/src/app/
CMD python3 manage.py run -h 0.0.0.0
As larsks suggests in his comment, you need the file in the services/users directory. To understand why, an understanding of the "context" is useful.
Docker does not build on the client, it does not see your current directory, or other files on your filesystem. Instead, the last argument to the build command is passed as the build context. With docker-compose, this context defaults to the current directory, which you will often see as . in a docker build command, but you can override that as you've done here with ./services/users as your context. When you run a build, the very first step is to send that build context from the docker client to the server. Even when the client and server are on the same host (a common default, especially for desktop environments), this same process happens. Files listed in .dockerignore, and files in parent directories to the build context are not sent to the docker server.
When you run a COPY or ADD command, the first argument (or all but the last argument when you have multiple) refer to files from the build context, and the last argument is the destination file or directory inside the image.
Therefore, when you put together this compose file entry:
build:
context: ./services/users
dockerfile: Dockerfile-dev
with this COPY command:
COPY ./requirements.txt /usr/src/app/requirements.txt
the COPY will try to copy the requirements.txt file from the build context generated from ./services/users, meaning ./services/users/requirements.txt needs to exist, and not be excluded by a .dockerignore file in ./services/users.
I had a similar problem building an image with beryllium, and I solved this deleting it into the .dockerignore
$ sudo docker build -t apache .
Sending build context to Docker daemon
10.55MB Step 1/4 : FROM centos ---> 9f38484d220f Step 2/4 :
RUN yum install httpd -y
---> Using cache ---> ccdafc4ae476 Step 3/4 :
**COPY ./**beryllium** /var/www/html COPY failed: stat /var/snap/docker/common/var-lib-docker/tmp/docker-builder04301**
$nano .dockerignore
startbootstrap-freelancer-master
run.sh
pro
fruit
beryllium
Bell.zip
remove beryllium from that file
$ sudo docker build -t apache .
Sending build context to Docker daemon 12.92MB
Step 1/4 : FROM centos
---> 9f38484d220f
Step 2/4 : RUN yum install httpd -y
---> Using cache
---> ccdafc4ae476
Step 3/4 : COPY ./beryllium /var/www/HTML
---> 40ebc02992a9
Step 4/4 : CMD apachectl -DFOREGROUND
---> Running in dab0a406c89e
Removing intermediate container dab0a406c89e
---> 1bea741cfb65
Successfully built 1bea741cfb65
Successfully tagged apache:latest

Why can't I access container with Dockerfile and but can access with docker-compose?

I am trying to learn Docker. I have a Hello World Django server application. When I try to run my server using a Dockerfile, my server is unreachable. But when I use docker-compose, I am able to access it.
My question is why, especially when they are quite similar.
My Dockerfile:
FROM python:3
# Set the working directory to /app
WORKDIR /bryne
# Copy the current directory contents into the container at /app
ADD . /bryne
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
# EXPOSE port 8000 to allow communication to/from server
EXPOSE 8000
# CMD specifcies the command to execute to start the server running.
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
# done!
Commands used when running server using Dockerfile:
docker build -t swyne-latest
docker run swyne-latest
Result: Cannot access server at 127.0.0.1:8000
My docker-compose.yml:
version: '3'
services:
web:
build: .
command: bash -c "python manage.py makemigrations && python manage.py migrate && python manage.py runserver 0.0.0.0:8000"
container_name: swyne
volumes:
- .:/bryne
ports:
- "8000:8000"
Commands used when running server using docker-compose:
docker-compose up
Result: Able to access my server at 127.0.0.1:8000
Thanks
Edit: Output from Dockerfile build:
$ docker build -t swyne-latest .
Sending build context to Docker daemon 60.15MB
Step 1/6 : FROM python:3
3: Pulling from library/python
05d1a5232b46: Already exists
5cee356eda6b: Already exists
89d3385f0fd3: Already exists
80ae6b477848: Already exists
28bdf9e584cc: Already exists
523b203f62bd: Pull complete
e423ae9d5ac7: Pull complete
adc78e8180f7: Pull complete
60c9f1f1e6c6: Pull complete
Digest: sha256:5caeb1a2119661f053e9d9931c1e745d9b738e2f585ba16d88bc3ffcf4ad727b
Status: Downloaded newer image for python:3
---> 7a35f2e8feff
Step 2/6 : WORKDIR /bryne
---> Running in 9ee8283c6cc6
Removing intermediate container 9ee8283c6cc6
---> 5bbd14170c84
Step 3/6 : ADD . /bryne
---> 0128101457f5
Step 4/6 : RUN pip install --trusted-host pypi.python.org -r requirements.txt
---> Running in 55ab661b1b55
Collecting Django>=2.1 (from -r requirements.txt (line 1))
Downloading https://files.pythonhosted.org/packages/32/ab/22530cc1b2114e6067eece94a333d6c749fa1c56a009f0721e51c181ea53/Django-2.1.2-py3-none-any.whl (7.3MB)
Collecting pytz (from Django>=2.1->-r requirements.txt (line 1))
Downloading https://files.pythonhosted.org/packages/30/4e/27c34b62430286c6d59177a0842ed90dc789ce5d1ed740887653b898779a/pytz-2018.5-py2.py3-none-any.whl (510kB)
Installing collected packages: pytz, Django
Successfully installed Django-2.1.2 pytz-2018.5
Removing intermediate container 55ab661b1b55
---> dce5400552b2
Step 5/6 : EXPOSE 8000
---> Running in c74603a76b54
Removing intermediate container c74603a76b54
---> ee5ef2bf2999
Step 6/6 : CMD ["python", "manage.py", "runserver", "127.0.0.1:8000"]
---> Running in 4f5ea428f801
Removing intermediate container 4f5ea428f801
---> 368f73366b69
Successfully built 368f73366b69
Successfully tagged swyne-latest:latest
$ docker run swyne-latest
(no output)
I guess it's normal that unlike docker-compose up, docker run swyne-latest does not allow you to access the web application at 127.0.0.1:8000.
Because the docker-compose.yml file (which is read by docker-compose but not by docker itself) specifies many parameters, in particular the port mapping, which should otherwise be passed as CLI parameters of docker run.
Could you try running docker run -p 8000:8000 instead?
Also, I guess that the line command: bash -c "python manage.py makemigrations && python manage.py migrate && python manage.py runserver 0.0.0.0:8000" should probably put inside the Dockerfile itself with a CMD or ENTRYPOINT directive, not in the docker-compose.yml file.
Actually, I've just taken a look at the output of your docker build command and there is an orthogonal issue:
the command
CMD ["python", "manage.py", "runserver", "127.0.0.1:8000"]
should be replaced with
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
(See this SO answer for more feedback on this issue, albeit in another language, Java instead of Python.)
As an aside, the complete command to compile the Dockerfile is not docker build -t swyne-latest but docker build -t swyne-latest . (with the final dot corresponding to the folder of the Docker build context).

Can't access running Docker container in browser

I'm working behind a corporate proxy. I'm on Windows 10 machine but I'm also running VMware. Inside VMware I'm running a Fedora 28 image. Because I'm behind a corporate proxy I have to run an NTLM proxy server on Windows 10 so that Fedora can connect to the internet.
I have everything set up and I can access the internet and pull docker images perfectly. I'm following this tutorial here on docker-compose.
This is my directory structure:
docker-compose-tut
├── commander
│ └── Dockerfile
└── docker-compose.yml
Dockerfile
FROM node:latest
ENV http_proxy=http://prx:3128
ENV https_proxy=http://prx:3128
ENV ftp_proxy=http://prx:3128
ENV no_proxy=localhost,127.0.0.1
RUN curl -L https://github.com/joeferner/redis-commander/tarball/v0.4.5 | tar zx
RUN npm install -g redis-commander
ENTRYPOINT ["redis-commander"]
CMD ["--redis-host", "redis"]
EXPOSE 8081
docker-compose.yml
backend:
image: redis:latest
restart: always
frontend:
build: commander
links:
- backend:redis
environment:
- ENV_VAR1 = some_value
ports:
- 8081:8081
environment:
- VAR1=value
restart: always
When I run the command docker-compose up -d I get the following output
[root#localhost docker-compose-tut]$ docker-compose up -d
Building frontend
Step 1/10 : FROM node:latest
---> b064644cf368
Step 2/10 : ENV http_proxy http://prx:3128
---> Using cache
---> f70ae2e24003
Step 3/10 : ENV https_proxy http://prx:3128
---> Using cache
---> 12a4e65a3874
Step 4/10 : ENV ftp_proxy http://prx:3128
---> Using cache
---> 77abdce2f8d7
Step 5/10 : ENV no_proxy localhost,127.0.0.1
---> Using cache
---> 467c4f25e4f7
Step 6/10 : RUN curl -L https://github.com/joeferner/redis-commander/tarball/v0.4.5 | tar zx
---> Using cache
---> e3f8b2d8ad64
Step 7/10 : RUN npm install -g redis-commander
---> Running in 3189b0fa1086
npm WARN deprecated ejs#0.8.8: Critical security bugs fixed in 2.5.5
When I enter the command docker-compose ps this is literally the output
Name Command State Ports
------------------------------
When I enter the command docker-compose --services the output is the following:
backend
frontend
If I open the browser and enter http://localhost:8081 the browser says that it can't establish a connection to http://localhost:8081.
What am I doing wrong?

Resources