I made a Dockerfile to run an ActiveMQ service from, and when I try to connect to the console on the host machine using http://127.0.0.1:8161/ in my web browser, it says 127.0.0.1 didn’t send any data. in Google Chrome. This is with running the docker image using docker run -p 61613:61613 -p 8161:8161 -it service_test bash.
However, when I run it using docker run --net host -it service_test bash, Google Chrome says 127.0.0.1 refused to connect., which leads me to believe I'm doing something by adding the --net flag but I'm not sure why it can't connect. Maybe a port forwarding issue?
My Dockerfile is as follows
FROM <...>/library/ubuntu:20.04
ADD <proxy certs>
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends software-properties-common && \
update-ca-certificates && \
add-apt-repository -y ppa:deadsnakes/ppa && \
apt-get update && \
apt-get install -y --no-install-recommends \
curl \
git \
python3.8 \
python3.8-venv \
python3.8-dev \
openjdk-11-jdk \
make \
&& apt-get clean && \
rm -rf /var/lib/apt/lists/*
WORKDIR /opt
RUN <point pip to certs>
RUN echo "timeout = 300" >> /etc/pip.conf
RUN curl -O https://bootstrap.pypa.io/get-pip.py && \
python3.8 get-pip.py
# Run python in a venv
ENV VIRTUAL_ENV=/opt/venv
RUN python3.8 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
# Update pip before continuing
RUN pip install --upgrade pip
# Get wheel
RUN pip install wheel
# add extra index url
RUN echo "extra-index-url = <url>" >> /etc/pip.conf
# Install ActiveMQ
ENV JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
ENV PATH="$JAVA_HOME/bin:$PATH"
RUN mkdir -p /opt/amq
RUN curl -kL \
http://archive.apache.org/dist/activemq/5.16.3/apache-activemq-5.16.3-bin.tar.gz \
>> /opt/amq/apache-activemq-5.16.3-bin.tar.gz && \
tar -xzf /opt/amq/apache-activemq-5.16.3-bin.tar.gz --directory /opt/amq
ENV PATH="/opt/amq/apache-activemq-5.16.3/bin:$PATH"
# Expose ports 61613 and 8161 to other containers
EXPOSE 61613
EXPOSE 8161
COPY <package>.whl <package>.whl
RUN pip install <package>
Note: Some sensitive info was removed, anything surrounded by <> has been hidden.
For context, I am running activemq from the container using activemq console, and trying to connect to it from my host OS using Google Chrome.
Got it to work!
For those having the same issue, I resolved it by changing the IP address in jetty.xml from 127.0.0.1 to 0.0.0.0. I am now able to connect to my containerized AMQ instance from my host OS.
Related
Wanted to turn my python script into api using Docker.
This is what the Dockerfile looks like:
FROM python:3.9-slim
WORKDIR /app
RUN apt-get update && apt-get install -y \
build-essential \
software-properties-common \
git \
&& apt-get install poppler-utils -y \
&& apt-get -y install tesseract-ocr \
&& apt-get update \
&& apt-get install ffmpeg libsm6 libxext6 -y \
&& apt-get install default-libmysqlclient-dev -y \
&& rm -rf /var/lib/apt/lists/*
COPY . .
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"]
Docker build container just fine. It is running
No errors within the Docker:
I press the link and its just http://0.0.0.0/
I am using PyCharm and python, so I binded the port in PyCharm too
Did anyone run into similar problem? I am new to Docker and might've missed something obvios, sorry.
I tried adding port manually http://0.0.0.0:80/ and http://0.0.0.0:80/Docs
but nothing shows up.
I build similar project with exactly same parameters but this one doesn't work.
What your program is showing you is what address it has bound to. 0.0.0.0 means that it'll accept connections from anywhere and 0.0.0.0 isn't the actual address you need to talk to to reach your program.
You've mapped port 80 in the container to port 80 on the host, so you should be able to reach your program at http://localhost:80/. Since port 80 is the default for http, you can also just use http://localhost/.
I have a docker image successfully built on my mac. I am running this image by typing docker run -p 8000:8000 .
Django server is up and ready to accept requests. but when I request to given URL via postman I am getting an error: socket hangs up.
Here is my docker file.
FROM python:3.6-slim-stretch
ENV PYTHONUNBUFFERED 1
WORKDIR /app
COPY requirements.txt requirements.txt
RUN apt-get -y update
RUN apt-get install -y --fix-missing \
build-essential \
cmake \
gfortran \
git \
wget \
curl \
graphicsmagick \
libgraphicsmagick1-dev \
libatlas-base-dev \
libavcodec-dev \
libavformat-dev \
libgtk2.0-dev \
libjpeg-dev \
liblapack-dev \
libswscale-dev \
pkg-config \
python3-dev \
python3-numpy \
software-properties-common \
zip \
&& apt-get clean && rm -rf /tmp/* /var/tmp/*
RUN cd ~ && \
mkdir -p dlib && \
git clone -b 'v19.9' --single-branch https://github.com/davisking/dlib.git dlib/ && \
cd dlib/ && \
python3 setup.py install --yes USE_AVX_INSTRUCTIONS
RUN pip3 install --default-timeout=100 future
RUN pip3 install -r requirements.txt
COPY . .
CMD python3 manage.py makemigrations face && python3 manage.py migrate && python3 manage.py runserver
The browser also responding by the server didn't send data.
Please help me.
Django's runserver command listens on 127.0.0.1 (the loopback interface) by default, since it's meant for development, not production.
In order for something to be -publishable from a Docker container to the outside world, it needs to listen on 0.0.0.0, i.e. all interfaces.
Add that to your runserver invocation...
CMD python3 manage.py migrate && python3 manage.py runserver 0.0.0.0:8000
Using this for DockerFile, on running with
docker run -p 5000:5000 flask_app:1.0
It runs but browser is showing 127.0.0.1 refused to connect.
RUN apt-get update \
&& apt-get install tesseract-ocr -y \
python3 \
#python-setuptools \
python3-pip \
&& apt-get clean \
&& apt-get autoremove
ADD . /home/App
WORKDIR /home/App
COPY requirements.txt ./
COPY . .
RUN pip3 install -r requirements.txt
VOLUME ["/data"]
EXPOSE 5000
ENTRYPOINT [ "python3" ]
CMD [ "app.py" ]```
You are probably listening on interface 127.0.0.1. You need to listen on 0.0.0.0, e.g. app.run(host="0.0.0.0", port=5000).
Basically the container and your host have different 127.0.0.1, so you need to bind to external IPs. For more details, and diagrams, see https://pythonspeed.com/articles/docker-connection-refused/
I have my windows docker installed in my windows 10 machine. Now I need to install python and ansible in my docker container.
I got few references to install python and ansible in a Linux machine. But I could not find a source how to install python 3 and ansible in a windows10 docker container.
Once python is installed I can try to install ansible using pip command. But for that I am not sure how to start with python installation first. In docker I have installed Jenkins, and want to run my ansible playbooks in Jenkins. Kindly help. Thanks!
I build an ansible image periodically tracking the devel branch:
# syntax=docker/dockerfile:experimental
FROM ubuntu:18.04
ENV DEBIAN_FRONTEND noninteractive
ENV PATH /ansible/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
RUN apt-get update && \
apt-get -y install \
git \
openssh-client \
python3.7 \
python3.7-dev \
python3-pip \
python3-setuptools \
python3-pygit2 \
build-essential \
libssl-dev \
libffi-dev \
man
RUN groupadd -g 1000 ansible && \
useradd -u 1000 -g ansible -d /home/ansible -m -k /etc/skel -s /bin/bash ansible
RUN mkdir -p -m 0600 ~/.ssh && \
ssh-keyscan github.com >> ~/.ssh/known_hosts
RUN --mount=type=ssh git clone -b devel https://github.com/ansible/ansible.git /ansible && \
chown -R 1000:1000 /ansible
RUN python3 -m pip install -r /ansible/requirements.txt
RUN ln -s /usr/bin/python3 /usr/bin/python
RUN echo '. /ansible/hacking/env-setup' >> /home/ansible/.bashrc
ENTRYPOINT ["/ansible/bin/ansible"]
Note:
ansible is not intended to be run from a windows control
server - you can use Linux containers on Windows
this example uses the docker build
enhancements
the image is configured following the common
environment
setup
for developing ansible modules
Build the image: DOCKER_BUILDKIT=1 docker build --rm --network host -t so:5776957 .
Run the container: docker run --rm --network host -e ANSIBLE_HOME=/ansible -e PYTHONPATH=/ansible/lib so:5776957 localhost -m ping
Instead of installing in container from yourself, you may try to use existing docker image which already have the same already installed. If you still want to build by yourself, you can look at the Dockerfile in the github repo.
https://hub.docker.com/r/zeeshanjamal16/ansibledocker
I'm running a simple Python Flask app using Gunicorn. I want to start the Gunicorn service then run a custom shell script after the service is up.
Something like this:
FROM python:3.6.5-slim
RUN apt-get update \
&& apt-get clean \
&& apt-get install -qq -y git build-essential libpq-dev --no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
CMD ["entrypoint.sh"]
With the objective being to run my_custom_script.sh after the Gunicorn service starts (currently will not run):
#!/bin/sh
echo "Waiting for postgres..."
while ! nc -z postgres 5432; do
sleep 0.1
done
echo "PostgreSQL started"
gunicorn -b 0.0.0.0:5000 manage:app
bash my_custom_script.sh
The script just builds the databases, runs some tests and adds some fact data.