Cannot see my server in the browser - docker

I'm using Docker Toolbox on Windows 10.
I'm starting a server using python manage.py runserver 0.0.0.0:8000
I'm getting the response Starting development server at http://0.0.0.0:8000/
However when I'm going to http://127.0.0.1:8000/ in my browser, it's not working.
Any idea? What should I check?
I've tried docker run -p 8000:8000 my_image but I get Bind for 0.0.0.0:8000 failed: port is already allocated.
Here is my docker-compose.yml file:
version: '2'
services:
postgres:
image: postgres
restart: on-failure
redis:
image: redis:alpine
restart: on-failure
elasticsearch:
image: "elasticsearch:2.4-alpine"
restart: on-failure
ports:
- "9200:9200"
politikon:
image: *****
links:
- postgres
- redis
- elasticsearch
ports:
- "2233:22"
- "8000:8000"
dns:
- 8.8.8.8
- 8.8.4.4
environment:
- "POSTGRES_PORT_5432_TCP_PORT=5432"
- "POSTGRES_PORT_5432_TCP_ADDR=postgres"
- "DJANGO_SETTINGS_MODULE=*****.settings.dev"
- "BONSAI_URL=http://elasticsearch:9200/"
- "ELASTIC_USERNAME=*****"
- "ELASTIC_PASSWORD=*****"
volumes:
- $PWD:/app
restart: on-failure
And here is my Docker file (without some irrelevant lines):
FROM ubuntu:trusty
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update -y -qq --fix-missing
RUN apt-get install -y wget
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main" >> /etc/apt/sources.list.d/pgdg.list
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
RUN apt-get update -y -qq --fix-missing
RUN apt-get upgrade -y -qq
RUN apt-get install -y python-dev python-pip postgresql-client-common postgresql postgresql-contrib postgresql-9.5 libpq-dev git libmemcached-dev curl openssh-server mercurial gettext vim libjpeg-dev libjpeg8-dev
RUN echo "locale-gen en_US.UTF-8" >> /etc/profile
RUN echo "dpkg-reconfigure locales" >> /etc/profile
RUN echo "export VISIBLE=now" >> /etc/profile
RUN echo "KexAlgorithms=diffie-hellman-group1-sha1" >> /etc/ssh/sshd_config
RUN echo "PermitUserEnvironment=yes" >> /etc/ssh/sshd_config
ENV PORT 8000
EXPOSE 8000
EXPOSE 22
RUN touch /root/.bash_profile
RUN echo "cd /app" >> /root/.bash_profile
RUN mkdir /root/.ssh/
RUN touch /root/.ssh/environment
CMD env >> /root/.ssh/environment; export -p | grep _ >> /etc/profile; /usr/sbin/sshd -D;
ADD /requirements.txt /app/
WORKDIR /app
RUN apt-get install zlib1g-dev
RUN pip install -r requirements.txt
CMD tail -f LICENSE

Related

Docker not loading files from npm run serve

I have a development environment where I run npm run serve in my local terminal and then docker-compose up -d in a different terminal to run the services I need to start my system.
I have an instance where I am attempting to run front-end tests, which I run inside of a running container using nightwatchJS, and for some reason the test runner is not accessing the files loaded from npm run serve. Quite literally when I print out a screenshot using the test runner the page looks as if I have canceled running npm run serve, however when I go to the page 127.0.0.1 in my browser, everything is loading as usual.
I think my issue is that the test is being run inside of a docker container like so:
docker-compose exec web bash -c "npx nightwatch ...file"
where that specific instance is not running npm run serve but I am confused as to why it works when I hit the browser personally. I have tried exposing ports in the Dockerfile but that does not work.
Can anybody point me in the right direction?
Here is my Dockerfile:
FROM python:3.8.5-slim-buster
# the first 2 prevent Python from writing out pyc files or from buffering stdin/stdout
# the others are Node
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV NVM_DIR /usr/local/nvm
ENV NODE_VERSION 12.7.0
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
# the man1 directory is not present for slim-buster so we add that and then install all of the default system based dependencies
# NOTE...TOP LAYERS ARE CACHED FIRST!!!!
RUN mkdir -p /usr/share/man/man1 \
&& apt-get clean && apt-get update -y && apt-get install pdftk-java curl git -y \
&& curl --silent -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.2/install.sh | bash \
&& apt-get install zlib1g-dev libjpeg-dev python3-pythonmagick inkscape xvfb poppler-utils libfile-mimeinfo-perl qpdf libimage-exiftool-perl ufraw-batch ffmpeg gcc procps -y \
&& apt-get clean && apt-get autoclean
# SELINUM
# get wget...
# Adding trusting keys to apt for repositories
RUN apt-get install gnupg -y && apt-get install wget -y \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list' \
&& apt-get update -y \
&& apt-get install google-chrome-stable -y \
&& apt-get install unzip -yqq
# Set up Chromedriver Env Vars
ENV CHROMEDRIVER_VERSION 87.0.4280.20
ENV CHROMEDRIVER_DIR /chromedriver
# make directory for it...
RUN mkdir $CHROMEDRIVER_DIR
# Download and install Chromedriver
RUN wget -q --continue -P $CHROMEDRIVER_DIR "http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip" \
&& unzip $CHROMEDRIVER_DIR/chromedriver* -d $CHROMEDRIVER_DIR \
&& rm "$CHROMEDRIVER_DIR/chromedriver_linux64.zip"
# Put Chromedriver into the PATH
ENV PATH $CHROMEDRIVER_DIR:$PATH
# Set display port as an environment variable
ENV DISPLAY=:99
# SELINUM
## NIGHTMARE
#RUN apt-get install wget -y && wget http://selenium-release.storage.googleapis.com/2.44/selenium-server-standalone-2.44.0.jar -P /bin/
#RUN apt install default-jre -y
#RUN apt-get install -y xvfb x11-xkb-utils xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic x11-apps clang libdbus-1-dev libgtk2.0-dev libnotify-dev libgconf2-dev libasound2-dev libcap-dev libcups2-dev libxtst-dev libxss1 libnss3-dev gcc-multilib g++-multilib
# ensure node is installed, and at the end, make the working directory
RUN . $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default \
&& mkdir /code
# set working directory to /code...it was just made for this purpose
WORKDIR /code
# possible that these will cache so separate them from COPY . /code/
COPY requirements.txt /code/
# now install, this will normally also cache
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
# place this at the end because the code will always change...this will almost never cache...
COPY . /code/
EXPOSE 8001
EXPOSE 8888
Here is my compose file:
version: '3.4'
services:
redis:
image: redis
ports:
- "6379"
restart: unless-stopped
networks:
main:
aliases:
- redis
postgres:
image: postgres:12
ports:
- "5432:5432"
env_file: ./.env
restart: unless-stopped
volumes:
- pgdata:/var/lib/postgresql/data
networks:
main:
aliases:
- postgres
#access by going to localhost:16543
#when adding a server to the serve list
#the hostname is postgres
#the username is postgres
#the password is postgres
pgadmin:
image: dpage/pgadmin4
links:
- postgres
depends_on:
- postgres
env_file: ./.env
restart: unless-stopped
ports:
- "16543:80"
networks:
main:
aliases:
- pgadmin
celery:
build:
network: host
context: .
dockerfile: Dockerfile-dev # use docker-dev because production npm installs and npm builds
command: python manage.py celery
env_file: ./.env
restart: unless-stopped
volumes:
- .:/code
- tmp:/tmp
links:
- redis
depends_on:
- redis
networks:
main:
aliases:
- celery
web:
build:
network: host
context: .
dockerfile: Dockerfile-dev
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
- tmp:/tmp
ports:
- "8000:8000"
env_file: ./.env
restart: unless-stopped
links:
- postgres
- redis
- celery
- pgadmin
depends_on:
- postgres
- redis
- celery
- pgadmin
networks:
main:
aliases:
- web
volumes:
pgdata:
tmp:
networks:
main:

Docker not found inside container instead of passed daemon as a volume

Can anybody help me? This docker-compose file worked for me a few days ago with docker command available inside the container, but now it throws: docker: not found inside.
The docker daemon on the host is on /usr/local/bin/docker. It's a mac.
Any idea? Could you help me to try this on yours guys? Thks
version: '3'
services:
jenkins:
container_name: jenkins
image: jenkins
build:
context: jenkins
# entrypoint: /var/jenkins_home/entrypoint
ports:
- "8080:8080"
volumes:
- $PWD/jenkins_home:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
environment:
- AWS_ACCESS_KEY_ID=xxxxx
- AWS_SECRET_ACCESS_KEY=xxxxx
networks:
- net
remote_host:
container_name: remote-host
image: remote-host
build:
context: centos
volumes:
- /var/run/docker.sock:/var/run/docker.sock
networks:
- net
db_host:
container_name: db
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=1234
networks:
- net
networks:
net:
Dockerfile for remote_host service is the following:
RUN yum install -y openssh-server
RUN useradd remote_user && \
echo "1234" | passwd remote_user --stdin && \
mkdir /home/remote_user/.ssh && \
chmod 700 /home/remote_user/.ssh
COPY remote-key.pub /home/remote_user/.ssh/authorized_keys
RUN chown remote_user:remote_user -R /home/remote_user && \
chmod 600 /home/remote_user/.ssh/authorized_keys
RUN /usr/sbin/sshd-keygen > /dev/null 2>&1
RUN yum install -y mysql
RUN yum install -y epel-release && \
yum install -y python-pip && \
pip install --upgrade pip && \
pip install awscli
# CMD /usr/sbin/sshd-keygen -D
CMD tail -f /dev/null

Docker - No such file or directory. Copy does not copy all files

Dockerfile does not completely copy all files from the local directory.
I don’t understand why he copies the folder from the backend, but it doesn’t have all the files.
Thanks for help..
structure:
docker/
django/
/Dockerfile
/backend/
requirements.txt
src/
angular4/
/Dockerfile
/client
docker-compose.yml
docker-compose.yml
version: '3'
services:
db:
image: postgres:9.6
hostname: db
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: alinta
ports:
- "5432:5432"
backend:
build: ./django
image: alinta
command: python3 manage.py runserver 0.0.0.0:8000
volumes:
- .:/var/www/alinta/
ports:
- "8000:8000"
depends_on:
- db
migration:
image: alinta
command: python3 manage.py migrate --noinput
volumes:
- .:/var/www/alinta/
depends_on:
- db
frontend:
build: ./angular4
volumes:
- .:/var/www/alinta
ports:
- "4200:4200"
Dockerfile (django):
FROM postgres:9.6
RUN apt-get update && apt-get install -q -y postgresql-9.6 postgresql-client-9.6 postgresql-contrib-9.6 postgresql-client-common postgresql-common
#RUN echo postgres:postgres | chpasswd
#RUN pg_createcluster 9.6 main --start
#RUN /etc/init.d/postgresql start
FROM python:3.7
MAINTAINER Nikita Alekseev <nik_alekseev#outlook.com>
# Alinta
# Version: 1.0
# Install Python and Package Libraries
RUN apt-get update && apt-get upgrade -y && apt-get autoremove && apt-get autoclean
RUN apt-get install -y \
libffi-dev \
libssl-dev \
libxml2-dev \
libxslt-dev \
libjpeg-dev \
libfreetype6-dev \
zlib1g-dev \
net-tools \
vim
RUN apt-get install -y \
python3-pip \
python3-dev \
python3-virtualenv \
libpq-dev \
postgresql \
postgresql-contrib \
nginx \
curl
RUN pip3 install virtualenv
# Project Files and Settings
ARG PROJECT=alinta
ARG PROJECT_DIR=/var/www/${PROJECT}
RUN mkdir -p $PROJECT_DIR/backend/src
RUN mkdir -p $PROJECT_DIR/backend/src/static
RUN mkdir -p $PROJECT_DIR/backend/src/media
#WORKDIR $PROJECT_DIR
COPY ./backend /var/www/alinta/
WORKDIR $PROJECT_DIR/backend
RUN virtualenv -p python3.7 --no-site-packages env
RUN /bin/bash -c "source env/bin/activate"
RUN pip3 install -r requirements.txt
WORKDIR $PROJECT_DIR/backend/src
EXPOSE 8000
docker-compose build
ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'
For your Dockerfile your requirements.txt is in backend directory, and not on the same level, so adding or copying it will make it visible:
so add:
ADD ./backend/requirements.txt requirements.txt
or
COPY ./backend/requirements.txt requirements.txt
before you run
RUN pip3 install -r requirements.txt
Just copying backend directory as:
COPY ./backend /var/www/alinta/
will not allow Docker to know the context of your requrements.txt. Using ADD or COPY will instruct Docker how to locate file.

Docker container killed after Ctrl +C

I have a nginx and php-fpm containers.
When I'am in my php container in a projet and I exec any command (like vendor/bin/behat or composer update) who takes time and I click on CTRL+C. I'm ejected from the container. I don't know why.. When I click on CTRL+C without executing commands i don't have the problem.
Any idea ?
This is my docker-compose.yml file :
version: '3'
services:
nginx:
image: nginx:latest
restart: always
ports:
- "80:80"
volumes:
- ./nginx/conf:/etc/nginx/custom_conf
- ./nginx/hosts:/etc/nginx/conf.d/
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./logs/nginx:/var/log/nginx
- ..:/var/www
networks:
my_network:
ipv4_address: 10.5.0.31
web:
build: .
restart: always
ports:
- "9000:9000"
- "5001:5001"
volumes:
- ./php/php.ini:/usr/local/etc/php/conf.d/30-php.ini
- ./php/app2.conf:/usr/local/etc/php/conf.d/app2.conf
- ./keys/:/var/www/.ssh
- ./custom-hosts:/etc/custom-hosts
- ..:/var/www
- ./supervisor/supervisord.conf:/etc/supervisor/supervisord.conf
- ./supervisor/conf/:/etc/supervisor/conf.d/
networks:
my_network:
ipv4_address: 10.5.0.20
tty: true
db:
build: mysql
restart: always
ports:
- "3306:3306"
volumes:
- ./logs/mysql:/var/log/mysqld.log
- ./mysql/sql:/var/dumps
- data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_USER=root
- MYSQL_PASSWORD=root
networks:
my_network:
ipv4_address: 10.5.0.23
volumes:
data:
driver: local
networks:
my_network:
driver: bridge
ipam:
config:
- subnet: 10.5.0.0/16
My php-fpm Dockerfile:
FROM php:7.1-fpm
WORKDIR /var/www
RUN apt-get update && apt-get install -y wget git vim sudo unzip apt-utils
RUN apt-get install -y gnupg
RUN apt-get update
### composer
RUN cd /usr/src
RUN curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
# xdebug
RUN pecl install xdebug-2.5.0 \
&& docker-php-ext-enable xdebug
### php extension
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
RUN apt-get clean && apt-get update && apt-get -y --fix-missing install libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng-dev \
libicu-dev \
libxml2-dev \
g++ \
zlib1g-dev
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install -j$(nproc) gd
RUN docker-php-ext-install exif
RUN docker-php-ext-install pdo_mysql
RUN docker-php-ext-configure intl
RUN docker-php-ext-install intl
RUN apt-get install -y libzip-dev
RUN docker-php-ext-install zip
### main
RUN usermod -u 1000 www-data
RUN chmod -R 777 /var/www/
RUN chown -R www-data:www-data /var/www
ADD bash_profile /var/www/.bash_profile
ADD script.sh /usr/bin/script.sh
RUN chmod 755 /usr/bin/script.sh
CMD ["bin/bash"]
ENTRYPOINT ["script.sh"]
EXPOSE 9000
And my script.sh :
#! /bin/bash
php-fpm &
echo "Serveur de développement Cartesia Education"
cat /etc/custom-hosts >> /etc/hosts
dpkg-reconfigure -f noninteractive tzdata
echo "LC_TIME=fr_FR.utf8" >> /etc/environment
service supervisor start
exec su -l www-data -s /bin/bash
Thank you for your help.
Have you tried running the container in detached mode (-d option)?
> docker run -d [CONTAINER-NAME]
This will cause the container to run in the background. You can still SSH into the running container by:
> docker exec -it [CONTAINER-NAME] bash
Exiting the container once in will not terminate it.

Rails cannot find PSQL DB in docker

I'm running a rails app in docker. Whenever i shut down a container and restart it, I get FATAL: database "my_app_dev" does not exist and have to manually recreate it and run migrations. I have been unable to find a working solution for it.
Here are my docker files:
FROM ruby:2.5.1
RUN \
echo "deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main" >> /etc/apt/sources.list.d/pgdg.list && \
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
apt-get update -qq && \
curl -sL https://deb.nodesource.com/setup_10.x | bash - && \
apt-get install -y build-essential libssl-dev libssl-dev openssl \
nodejs postgresql-client-9.6 default-jre python python-dev python-pip groff-base vim && \
apt-get clean && \
mkdir /my_app
WORKDIR /my_app
COPY Gemfile Gemfile
RUN bundle check || bundle install
COPY . /cider
CMD ["rails", "server", "-b", "0.0.0.0", "-p", "3000"]
docker-compose.yml
version: '3'
services:
web:
build: .
container_name: my-web
tty: true
stdin_open: true
volumes:
- app_sync:/app:nocopy
- node_modules:/app/node_modules
ports:
- '127.0.0.1:3000:3000'
depends_on:
- db
env_file:
- .env
db:
image: postgres:9.6
ports:
- '127.0.0.1:5435:5432'
volumes:
- pg-data:/var/lib/postgrsql/data
volumes:
node_modules:
pg-data:
driver: local
app_sync:
external: true
Thanks.

Resources