I'm new to docker and I'm trying to add jupyter and python to my docker image based on Rocker (I want to have both python and R). I was able to install python3and jupyter with the dependencies. Image was created successfully. After running container I have access to RStudio server on port 7878, but unfortunately on port 8888 jupyter is not working.
My Dockerfile looks like this :
FROM rocker/rstudio:3.5.0
# Basic dependencies
RUN apt-get update && apt-get install -y \
libcurl4-gnutls-dev \
libssl-dev \
libpng-dev \
vim \
nano \
libxml2 \
libxml2-dev \
curl \
gnupg2 \
build-essential libssl-dev \
libpq-dev \
ssh
SHELL ["/bin/bash", "-c"]
# Install python3 and pip3
RUN apt-get update && apt-get install -y python3 \
python3-pip \
build-essential
# Install jupyter
RUN pip3 install jupyter
EXPOSE 8888
RUN mkdir /notebooks
CMD jupyter notebook --no-browser --ip 0.0.0.0 --allow-root --port 8888 /notebooks
CMD ["/init"]
Build and run:
docker build -f Dockerfile -t user/my_docer:1.0 .
docker run -d --name my_docker -p 8787:8787 -p 8888:8888 -v `pwd`:/mnt user/my_docer:1.0
You cannot use several CMD instructions - the second one overrides the first. If you need several processes to run in your container, which is treated as a bad practice, better use software like supervisord.
Another option is putting all stuff in a single CMD instruction like
CMD ["/bin/bash", "-c", "'jupiter blahblah && /init'"]
Related
I wrote a dockerfile to build a clashserver in ubuntu container. However, when I tried to stop the container, the docker just got stuck. There is no any error code or any answer from the terminal.
I think some disharmony command appeared in the dockerfile.
This is my dockerfile:
FROM ubuntu:latest
RUN cp /etc/apt/sources.list /etc/apt/sources.list.backup \
&& apt-get update -y \
&& apt-get upgrade -y \
&& apt-get clean \
&& apt-get autoclean \
COPY clash-linux-amd64 /bin/clash_run
RUN mkdir /etc/clash \
&& chmod +x /bin/clash_run
EXPOSE 7890
EXPOSE 7891
EXPOSE 9090
CMD ["/bin/clash_run","-d","/etc/Clash/"]
If you want to pull the docker image:cfbsks/clash_ubuntu:v0.1
Trying to run a decentralized vpn inside of a docker image. The issue im running to I think has to do with my running and installed kernels are different. I have to run modprobe wireguard in my docker file and its returning modprobe: FATAL: Module wireguard not found in directory /lib/modules/5.10.25-linuxkit I know the issue is related to the running kernels but im not sure what the fix would be. Heres my current Dockerfile.
FROM ubuntu:20.04
USER root
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \
git \
gcc \
make \
musl-dev \
unbound \
libtool \
g++ \
file \
automake \
autoconf \
libssl-dev \
libexpat-dev \
bison \
systemd \
iproute2 \
sudo \
wireguard-tools
RUN systemctl enable systemd-resolved
COPY . /sentinelnode /bin/
COPY . /.sentinelnode /root/
COPY . /hnsd /bin/
RUN chmod +x /bin/sentinelnode
RUN chmod +x /bin/hnsd
RUN sudo modprobe wireguard
RUN cd $HOME
CMD sentinelnode start
I am running a FastAPI application in docker. The backend is composed of multiple .py scripts, which train several machine learning models. The FastAPI returns the results. I have docker running and everything is just fine. However, when the modeling takes longer (by using several hyperparameter search loops), I receive an err_empty_response from my dockerized App. Without docker everything is fine. I suppose, it is some timeout issue.
I have added "shutdown-timeout": 600 in the config.v2.json file in var/lib/docker/containers (I am on ubuntu 18.04), but this did not help.
This is my dockerfile:
FROM ubuntu:18.04
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Europe/Moscow
RUN apt-get update && apt-get install -y curl wget gcc build-essential
#install python 3.9
RUN apt update
RUN apt install software-properties-common -y
RUN add-apt-repository ppa:deadsnakes/ppa
RUN apt install python3.9 -y
RUN ln -s /usr/bin/pip3 /usr/bin/pip
RUN ln -s /usr/bin/python3.9 /usr/bin/python
# install conda
RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-4.5.12-Linux-x86_64.sh -O ~/miniconda.sh && \
/bin/bash ~/miniconda.sh -b -p /opt/conda
# create env with python 3.9
RUN /opt/conda/bin/conda create -y -n myenv python=3.9
RUN apt install -y -q build-essential python3-pip python3-dev
RUN pip3 install -U pip setuptools wheel
#install python environment/libraries
COPY requirements.txt /app/requirements.txt
ENV PATH=/opt/conda/envs/myenv/bin:$PATH
RUN pip3 install gunicorn uvloop httptools
RUN pip3 install -r /app/requirements.txt
RUN pip3 install -U kaleido
COPY projectfolder/ /projectfolder/
RUN ls -la /projectfolder/*
WORKDIR /projectfolder
EXPOSE 80
ENTRYPOINT /opt/conda/envs/myenv/bin/gunicorn \
-b 0.0.0.0:80 \
-w 4 \
-k uvicorn.workers.UvicornWorker main:app \
--chdir /projectfolder
This is a sample FastAPI app, just for demo. The sleep time mimicks the timeout:
from fastapi import FastAPI
import uvicorn
app = FastAPI()
#app.get("/")
async def root():
time.sleep(150)
return {"message": "Hello World from docker"}
if __name__ == "__main__":
uvicorn.run(app)
I launch docker with
sudo docker build -t myproject .
sudo docker run -it --rm --name my-running-app -p 80:80 myproject
and open localhost in chrome.
So the question is: how can I extend the timeout, if this is the issue (most likely)?
Ok, after experimenting a bit, I found out that the issue was not with docker timeout, but with FastAPI. To change that, I modified the Entrypoint definiton in the dockerfile and set the timeout setting:
ENTRYPOINT /opt/conda/envs/myenv/bin/gunicorn \
-b 0.0.0.0:80 \
-w 4 \
--timeout 600 \
-k uvicorn.workers.UvicornWorker main:app
I have a docker file like this :
FROM ubuntu:12.04
MAINTAINER me <me#c.com>
RUN apt-get -y update
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install supervisor \
apache2 \
mysql-server \
php5 \
libapache2-mod-php5 \
php5-mysql \
php5-mcrypt
#ssh
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:root' | chpasswd
RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed 's#session\s*required\s*pam_loginuid.so#session optional pam_loginuid.so#g' -i /etc/pam.d/sshd
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
EXPOSE 22 80
ADD ./supervisord.conf /etc/supervisor/conf.d/supervisord.conf
CMD ["/usr/bin/supervisord"]
My question is how do I add a couchdb server into this docker file?
I can get a built-in couchdb docker image from here : https://hub.docker.com/r/klaemo/couchdb/, but how do I create a image like this my self? I can't find any documentation regarding the process!
I spent 3 hours tried to googled but got no luck, so I will take the risk to ask even if this is a dump question!
Is there a specific version of couchdb that you want in your docker container?
If not, since you are using Ubuntu 12.04 as your base image, you can get the couchdb 1.0.1 binaries from the Ubuntu 12.04/precise [universe] repository easily by adding couchdb to your apt-get list like this:
FROM ubuntu:12.04
MAINTAINER me <me#c.com>
RUN apt-get -y update
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install supervisor \
apache2 \
mysql-server \
php5 \
libapache2-mod-php5 \
php5-mysql \
php5-mcrypt \
couchdb
#[--Rest of your dockerfile goes here unchanged--]
You can alternatively use the PPA maintained by the Apache CouchDB team to get latest stable releases for your base image based on the officially released tar balls. For this option you can use the following dockerfile:
# To install the ppa finder tool in your docker container
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install python-software-properties
RUN add-apt-repository ppa:couchdb/stable -y
RUN apt-get -y update
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install supervisor \
apache2 \
mysql-server \
php5 \
libapache2-mod-php5 \
php5-mysql \
php5-mcrypt \
couchdb
#[--Rest of your dockerfile goes here unchanged--]
If you want the latest or a specific version of couchdb in your docker container then you might have to build couchdb from the source code. Note that this approach will require you to install many more packages (g++ erlang-dev erlang-manpages erlang-base-hipe erlang-eunit, libmozjs185-dev libicu-dev libcurl4-gnutls-dev libtool) onto your container to be able to build couchdb from source. However you may be able to purge/remove the packages that are required only to build couchdb. The complete list of dependencies can be found on the official couchdb build wiki on apache. If you really want THE latest version then you can refer to this dockerfile and add update your dockerfile accordingly. Here is a complete dockerfile [UNTESTED] for your ease of use:
FROM ubuntu:12.04
MAINTAINER me <me#c.com>
ENV COUCHDB_VERSION master
RUN groupadd -r couchdb && useradd -d /usr/src/couchdb -g couchdb couchdb
# download dependencies
RUN apt-get update -y -qq && apt-get install -y --no-install-recommends \
build-essential \
erlang-dev \
erlang-manpages \
erlang-base-hipe \
erlang-eunit \
erlang-nox \
erlang-xmerl \
erlang-inets \
libmozjs185-dev \
libicu-dev \
libcurl4-gnutls-dev \
libtool
RUN cd /usr/src && git clone https://git-wip-us.apache.org/repos/asf/couchdb.git \
&& cd couchdb && git checkout $COUCHDB_VERSION \
&& cd /usr/src/couchdb && ./configure && make
# You can optionally purge/remove the packages you installed to build the couchdb from source.
# permissions
RUN chmod +x /usr/src/couchdb/dev/run && chown -R couchdb:couchdb /usr/src/couchdb
USER couchdb
EXPOSE 5984 15984 25984 35984 15986 25986 35986
#[--Rest of your dockerfile can go here as required--]
I'm trying to build a LAMP container and I have already built several containers: httpd 2.4.23, redis 3.0.7, mysql 5.6.30 by compiling them myself from source code downloaded archives. I have based all of these above on the debian container.
Now that I'm doing the php 5.6.20 container it complains that it does not know about apache and mysql.
Here is the Dockerfile for the php container:
FROM debian
RUN apt-get update
RUN apt-get install -y build-essential;
RUN apt-get install -y cmake;
RUN apt-get install -y libfreetype6-dev libjpeg-dev libpng12-dev libcurl4-openssl-dev libbz2-dev libxml2-dev libxslt-dev libgd2-xpm-dev php5-imap libz-dev
WORKDIR /usr/bin/
COPY php-5.6.20.tar.gz /usr/bin/
RUN gzip -d php-5.6.20.tar.gz
RUN tar -xvf php-5.6.20.tar
RUN ln -s php-5.6.20 php
WORKDIR /usr/bin/php/
RUN ./configure \
--prefix=/usr/bin/ \
--with-apxs2=/usr/bin/apache/bin/apxs \
--with-config-file-path=/usr/bin/php-5.6.20/ \
--enable-libgcc \
--with-mysqli=/usr/bin/mysql/mysql_config \
--with-zlib-dir=/usr \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-gd \
--enable-gd-native-ttf \
--with-freetype-dir=/usr \
--enable-ftp \
--enable-xml \
--enable-zip \
--with-bz2 \
--enable-wddx \
--without-pear \
--enable-mbstring \
--with-curl
RUN make
RUN make install
I wonder if I should base it instead on: FROM httpd:2.4.23. But then I would need to base httpd on the mysql one, and / or on the redis one... I don't really like that setup.
I have also installed Docker Compose but I wonder if it could be helpful in my situation.
UPDATE: Here is the fully working Dockerfile
FROM debian
RUN apt-get update
RUN apt-get install -y build-essential;
RUN apt-get install -y cmake;
RUN apt-get install -y openssl libssl-dev;
RUN apt-get install -y libpcre3 libpcre3-dev
WORKDIR /usr/bin/
COPY httpd-2.4.23.tar.gz /usr/bin/
RUN gzip -d httpd-2.4.23.tar.gz
RUN tar -xvf httpd-2.4.23.tar
RUN ln -s httpd-2.4.23 httpd
COPY apr-1.5.2.tar.gz /usr/bin/httpd/srclib/
COPY apr-util-1.5.4.tar.gz /usr/bin/httpd/srclib/
WORKDIR /usr/bin/httpd/srclib/
RUN gzip -d apr-1.5.2.tar.gz
RUN gzip -d apr-util-1.5.4.tar.gz
RUN tar -xvf apr-1.5.2.tar
RUN tar -xvf apr-util-1.5.4.tar
RUN ln -s apr-1.5.2 apr;
RUN ln -s apr-util-1.5.4 apr-util
WORKDIR /usr/bin/httpd/
RUN ./configure \
--prefix=/usr/bin/apache \
--enable-rewrite \
--enable-deflate \
--enable-ssl
RUN make
RUN make install
RUN apt-get update
RUN apt-get install -y libncurses-dev
COPY mysql-5.6.30.tar.gz /usr/bin/
WORKDIR /usr/bin/
RUN gzip -d mysql-5.6.30.tar.gz
RUN tar -xvf mysql-5.6.30.tar
RUN ln -s mysql-5.6.30 mysql
WORKDIR /usr/bin/mysql/
RUN mkdir install; mkdir install/data; mkdir install/var; mkdir install/etc; mkdir install/tmp
RUN cd /usr/bin/mysql/; cmake \
-DCMAKE_INSTALL_PREFIX=/usr/bin/mysql/install \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/bin/mysql/install/data \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/bin/mysql/install/boost \
-DMYSQL_UNIX_ADDR=/usr/bin/mysql/install/tmp/mysql.sock
RUN make
RUN make install
RUN apt-get update
RUN apt-get install -y libfreetype6-dev libjpeg-dev libpng12-dev libcurl4-openssl-dev libbz2-dev libxml2-dev libxslt-dev libgd2-xpm-dev php5-imap libz-dev
WORKDIR /usr/bin/
COPY php-5.6.20.tar.gz /usr/bin/
RUN gzip -d php-5.6.20.tar.gz
RUN tar -xvf php-5.6.20.tar
RUN ln -s php-5.6.20 php
WORKDIR /usr/bin/php/
RUN ./configure \
--prefix=/usr/bin/php \
--with-apxs2=/usr/bin/apache/bin/apxs \
--with-config-file-path=/usr/bin/php-5.6.20/ \
--enable-libgcc \
--with-mysqli=/usr/bin/mysql/install/bin/mysql_config \
--with-zlib-dir=/usr \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-gd \
--enable-gd-native-ttf \
--with-freetype-dir=/usr \
--enable-ftp \
--enable-xml \
--enable-zip \
--with-bz2 \
--enable-wddx \
--without-pear \
--enable-mbstring \
--with-openssl
--with-curl
RUN make
RUN make install
ENTRYPOINT ["/usr/bin/apache/bin/apachectl", "start", "-D FOREGROUND"]
EXPOSE 80
# Build the container: docker build -t stephaneeybert/httpd:2.4.23 .
# Run the container: docker run -d -p 127.0.0.1:80:80 --name httpd stephaneeybert/httpd:2.4.23
# Check that the port is open: nmap -p 8081 localhost
If you need apache running in your container, you can install apache in your image with above Dockerfile, just as the same as you install the build-essential stuffs. Which means:
RUN apt-get install -y apache2
or similar command. If you also need the configure for this apache application, you can use ADD or COPY command to add your configure file from outside to inside of your container. More details can be found here.
If you need apache as an independent container, you can use docker-compse to achieve it. Start apache in another container, then use depends_on to config the dependency between your containers. You may use ports to change the port number of each container, so they can communicate between each other.