Port missing in Docker container - docker

I wanted to install apache, php7, postgres12, node, java in ubuntu:18.04 base image dockerfile and wanted to show postgre data in php file. After building and running the container when I checked the process status, the port is missing. I started docker recently so I am new in this. Here is my Dockerfile
FROM ubuntu:18.04
ARG DEBIAN_FRONTEND=noninteractive
# # Install openjdk-8-jdk
RUN apt-get update && \
apt-get install -y openjdk-8-jdk
RUN apt-get -y install nodejs
RUN apt-get update && apt-get -qq -y install curl
RUN apt-get -y install apache2
RUN apt-get -y install php7.2
RUN apt-get -y install libapache2-mod-php7.2
RUN rm -f /var/www/html/index.html
COPY . /var/www/html
RUN apt-get update && apt-get install -y gnupg2 && apt-get install -y wget
Run wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main" > /etc/apt/sources.list.d/pgdg.list
RUN apt-get update && apt-get install -y postgresql-12 postgresql-client-12
USER postgres
RUN /etc/init.d/postgresql start &&\
psql --command "CREATE USER docker WITH SUPERUSER PASSWORD 'docker';" &&\
createdb -O docker docker
RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/12/main/pg_hba.conf
RUN echo "listen_addresses='*'" >> /etc/postgresql/12/main/postgresql.conf
EXPOSE 80 5432
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
error
PS G:\Docker\test-docker-ubuntu-php\website> docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1fba1b8327fd test-custom-all "/usr/sbin/apache2ct…" 2 minutes ago Exited (1) 2 minutes ago test-custom
PS G:\Docker\test-docker-ubuntu-php\website> docker logs 1fba1b8327fd
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
(13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs
Action '-D FOREGROUND' failed.
The Apache error log may have more information.
Can you help me with this?
Thanks

Related

Container docker remains in exited status

Hi I'm building a docker image that starts Mysql, Elasticsearch and application, it completes the build of the image but when I run the container it doesn't start and remains in exited status.
DOCKERFILE:
FROM ubuntu:20.04
WORKDIR \\wsl.localhost\Ubuntu\home\marco\project\multiple-docker-container\backend
COPY . .
RUN apt update
RUN apt-get update
RUN apt-get install wget -y
RUN apt install apt-transport-https ca-certificates gnupg -y
RUN wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add -
RUN sh -c 'echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" > /etc/apt/sources.list.d/elastic-7.x.list'
RUN apt-get update -y
RUN apt-get install elasticsearch -y
RUN apt install mysql-server -y
RUN apt install npm -y
RUN npm install
RUN npm install nodemon
RUN apt install nodejs -y
EXPOSE 3306
EXPOSE 9200
EXPOSE 5000
COPY entrypoint.sh /bin/entrypoint.sh
RUN chmod +x /bin/entrypoint.sh
ENTRYPOINT ["/bin/entrypoint.sh"]
ENTRYPOINT.SH
#!/bin/sh
service elasticsearch start
service elasticsearch enable
service mysql start
npm start
I expect at least that it goes up, I would like to understand which is the problem since on WSL ubuntu gives me this problem while on the virtual machine it works

How to install Docker inside my ubuntu container?

I installed docker inside a container running on ubuntu:18.04 to run my nodejs app, I need docker installed inside this container because i need to dockerize an other small app
Her is my Dockerfile
FROM ubuntu:18.04
WORKDIR /app
COPY package*.json ./
# Install Nodejs
RUN apt-get update
RUN apt-get -y install curl wget dirmngr apt-transport-https lsb-release ca-certificates software-properties-common gnupg-agent
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN apt-get -y install nodejs
# Install Chromium
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
RUN apt-get update
RUN apt-get install -y google-chrome-unstable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst \
--no-install-recommends
RUN rm -rf /var/lib/apt/lists/*
# Install Docker
RUN curl -fsSL https:/download.docker.com/linux/ubuntu/gpg | apt-key add -
RUN apt-key fingerprint 0EBFCD88
RUN add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
RUN apt-get update -y
RUN apt-get install -y docker-ce docker-ce-cli containerd.io
RUN npm install
COPY . .
CMD [ "npm", "start" ]
EXPOSE 3000
When the container is up, i docker exec -it app bash.
If i do a service docker start then ps ax, got this
PID TTY STAT TIME COMMAND
115 ? Z 0:00 [dockerd] <defunct>
What can i do to be able to use docker inside the container or is there a docker image not using apk but apt-get ? Because when i need to use it, i got this error :
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
First thing better to use one of the base images, either for node-image and install docker and for docker-image and installed node, instead of creating image from scratch. All you need
FROM node:buster
RUN apt-get update
RUN apt install docker.io -y
RUN docker --version
ENTRYPOINT nohup dockerd >/dev/null 2>&1 & sleep 10 && node /app/app.js
second thing, The error Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?, The reason is you are not starting the docker process in the Dockefile, and also running multiple processes in the container is not recommended, as if Docker process dies you will not know the status, you have to put one process in the background.
CMD nohup dockerd >/dev/null 2>&1 & sleep 10 && node /app/app.js
and run
docker run --privileged -it -p 8000:8000 -v /var/run/docker.sock:/var/run/docker.sock your_image

Not able to access elasticsearch from docker container

elastic search is successfully running on docker container. but i'm not able access in browser. i mapped ports correctly. but the problem is in docker container. in container elasticsearch is mapped with localhost
127.0.0.1:9200
Dokcerfile
FROM ubuntu:16.04
MAINTAINER Rajesh Gurram
RUN apt-get update && \
apt-get install -y net-tools curl wget gnupg
RUN apt-get install -y software-properties-common
RUN add-apt-repository ppa:webupd8team/java && \
apt-get update && \
echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections && \
apt-get install -y oracle-java8-installer && apt-get clean
ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
RUN apt-get install apt-transport-https
RUN wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add - && \
echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-6.x.list && \
apt update && apt install -y elasticsearch
RUN sed -i 's/#network.host: 192.168.0.1/network.host: 0.0.0.0/g' /etc/elasticsearch/elasticsearch.yml
EXPOSE 9200 9300
Run Below command on Host machine it will resolve the issue
$ sysctl -w vm.max_map_count=262144
If you want to use docker to get an instance of Elasticsearch, you can read the following Guide:
https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html
You can also use docker images directly from elastic, if ubuntu is not a necessary base image:
https://www.docker.elastic.co/
If you want to upgrade to an ELK Stack later on, I recommend a docker volume for persistency purposes.

docker tool box docker build behind proxy is not working in windows

Installed docker tool box in windows.
Configured everything.
We have company proxy.
So to configure proxy, did the following.
Added environment variable.
set HTTP_PROXY=xx.xx.xx.xx:10015
set HTTPS_PROXY=xx.xx.xx.xx:10015
set NO_PROXY=192.168.99.100
Then created new virtual machine with following command
docker-machine create -d virtualbox --engine-env HTTP_PROXY=xx.xx.xx.xx:10015 --engine-env HTTPS_PROXY=xx.xx.xx.xx:10015 --engine-env NO_PROXY=192.168.99.100 default
And trying to build docker image with following command
docker build -t 1234567890.dkr.ecr.us-east-1.amazonaws.com/my-repository .
Here I have docker file, which has commands as following
FROM centos:latest
MAINTAINER me - ./build_centos.sh
# Set correct environment variables.
ENV HOME /root
ENV LANG en_US.UTF-8
ENV LC_ALL en_US.UTF-8
RUN yum install -y curl; yum upgrade -y; yum update -y; yum clean all
RUN yum -y update && yum -y install wget && yum -y install tar
RUN yum install -y wget unzip
RUN curl --insecure --junk-session-cookies --location --remote-name --silent --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u66-b17/jdk-8u66-linux-x64.rpm
RUN yum localinstall -y jdk-8u66-linux-x64.rpm
RUN rm jdk-8u66-linux-x64.rpm
ENV JAVA_HOME /usr/java/default
# RUN yum remove curl; yum clean all
# centos-java8U60-ssh
RUN yum -y install openssh-server initscripts
RUN echo "root:xxxxx" | chpasswd
RUN /usr/sbin/sshd-keygen
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
RUN mkdir /opt/myimage
COPY myjara-repository-0.0.1.jar /opt/myimage
WORKDIR /opt/myimage
EXPOSE 8091
CMD java -jar myimage-repository-0.0.1.jar
But I am getting following error
Cannot find a valid baseurl for repo: base/7/x86_64
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#7 - "Failed to connect to 2a01:c0:2:4:0:acff:fe1e:1e52: Network is unreachable"
The command '/bin/sh -c yum -y update && yum -y install wget && yum -y install tar' returned a non-zero code: 1
How to solve this?

Docker: Error response from daemon: no such id:

currently I try to launch docker image on deamon with docker run -d ID (after to launch this commande: docker build -t toto .)
But when I launch this commande: docker exec -it ID bash, I've got this error:
Error response from daemon: no such id: toto
My Dockerfile look like that:
# Dockerfile
FROM debian:jessie
# Upgrade system
RUN apt-get update && apt-get dist-upgrade -y --no-install-recommends
# Install TOR
RUN apt-get install -y --no-install-recommends tor tor-geoipdb torsocks
# INSTALL POLIPO
RUN apt-get update && apt-get install -y polipo
# INSTALL PYTHON
RUN apt-get install -y python2.7 python-pip python-dev build-essential libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev libxslt-dev libxml2-dev && apt-get clean
# INSTALL GIT
RUN apt-get install -y git-core
# INSTALL NANO
RUN apt-get install -y nano
# INSTALL SUPERVISOR
RUN apt-get install -y supervisor
# INSTALL SCRAPY and dependencies
RUN pip install lxml && pip install pyopenssl && pip install Scrapy && pip install pyopenssl && pip install beautifulsoup4 && pip install lxml && pip install elasticsearch && pip install simplejson && pip install requests && pip install scrapy-crawlera && pip install avro && pip install stem
# INSTALL CURL
RUN apt-get install -y curl
# Default ORPort
EXPOSE 9001
# Default DirPort
EXPOSE 9030
# Default SOCKS5 proxy port
EXPOSE 9050
# Default ControlPort
EXPOSE 9051
# Default polipo Port
EXPOSE 8123
# Configure Tor and Polopo
RUN echo 'socksParentProxy = "localhost:9050"' >> /etc/polipo/config
RUN echo 'socksProxyType = socks5' >> /etc/polipo/config
RUN echo 'diskCacheRoot = ""' >> /etc/polipo/config
RUN echo 'ORPort 9001' >> /etc/tor/torrc
RUN echo 'ExitPolicy reject *:*' >> /etc/tor/torrc
ENV PYTHONPATH $PYTHONPATH:/scrapy
WORKDIR /scrapy
VOLUME ["/scrapy"]
Thanks in advance.
In order to facilitate the usage of docker exec, make sure you run your container with a name:
docker run -d --name aname.cont ...
I don't see an entrypoint or exec directove in the Dockerfile, so do mention what you want to run when using docker run -d
(I like to add '.cont' as a naming convention, to remember that it is a container name, not an image name)
Then a docker exec aname.cont bash should work.
Check that the container is still running with a docker ps -a
When creating the container you should use the image name:
docker run -d --name my_toto toto
You cannot impose an ID when creating it. It's Docker who assigns the ID.
Then connecting
docker exec -it my_toto bash
A more quick way to do that is running directly
docker run -d -it -name my_toto toto bash
The container will still existing after you exit.

Resources