Add tcpdump docker image with base image node:10.0.0 - docker

How can I add tcpdump package in Dockerfile if the base image is node:10.0.0
Dockerfile:
FROM node:10.0.0
EXPOSE $SERVICE_PORT
USER node
RUN mkdir -p /home/node/
WORKDIR /home/node/
COPY package.json /home/node/
RUN npm install
COPY . /home/node/
CMD ["npm", "run", "staging"]
I want to trace the traffic in this container.

It is unnecessary to modify your image to access the network of the container. You can run a second container in the same network namespace:
docker run -it --net container:${container_to_debug} nicolaka/netshoot
From there, you can run tcpdump and a variety of other network debugging tools and see the traffic going to your other container. To see all the tools included in netshoot, see the github repo: https://github.com/nicolaka/netshoot

you base image is debian based, therefore use apt-get as your package manager. add to your dockerfile the following instructions:
USER root
RUN apt-get update -y; exit 0
RUN apt-get install tcpdump -y
explanation:
USER root - apt-get requires root permissions.
RUN apt-get update -y; exit 0 - i am adding exit 0 to tell docker i want to keep the build, even if apt-get couldn't get all of its mirror files
RUN apt-get install tcpdump -y - installation of the package.

Related

Rust compiler in jupyter lab docker instance

I am trying to install the rust compiler within a jupyter docker image. Here in the following the dockerfile:
FROM jupyter/scipy-notebook:python-3.10.5 as base
RUN pip install nb_black
USER root
RUN apt update && apt upgrade
RUN apt install build-essential -y
RUN apt install curl -y
USER jovyan
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
RUN pip install maturin
COPY ./docker_helpers /rust_inst
RUN chmod a+x /rust_inst/setup_rust.sh
RUN /rust_inst/setup_rust.sh
FROM base as prod
CMD ["jupyter", "lab", "--ip", "0.0.0.0"]
and the setup_rust.sh contains just an export statement:
#!/bin/bash
export PATH="$HOME/.cargo/bin:$PATH"
I need to use the root user initially for some permission denied, but after that the jovyan user is able to install all the necessary, or at least I do not get any error from docker at building time.
Does the jupyter docker structure mask the path variable, or make unavailable anything outside jovyan?
How can I have the rust compiler available from a terminal within jupyter?
I realised that the home directory is set to "/home/jovyan" itself, which in docker compose I overwrote with a volume in order to have dynamical code. Once I moved the volume I found the rust compiler in the scope of the jovyan user

Jenkins not starting in docker (Dockerfile included)

I am attempting to build a simple app with Jenkins in a docker container. I have the following Dockerfile:
FROM ubuntu:trusty
# Install dependencies for Flask app.
RUN sudo apt-get update
RUN sudo apt-get install -y vim
RUN sudo apt-get install -y curl
RUN sudo apt-get install -y python3-pip
RUN pip3 install flask
# Install dependencies for Jenkins (Java).
# Install Java 1.8.
RUN sudo apt-get install -y python-software-properties debconf-utils
RUN sudo apt-get install -y software-properties-common
RUN sudo add-apt-repository -y ppa:webupd8team/java
RUN sudo apt-get update
RUN echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 select true" | sudo debconf-set-selections
RUN sudo apt-get install -y oracle-java8-installer
# Install, start Jenkins.
RUN sudo apt-get install -y wget
RUN wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | apt-key add -
RUN echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list
RUN sudo apt-get update
RUN sudo apt-get install -y jenkins
RUN sudo /etc/init.d/jenkins start
COPY ./app /app
CMD ["python3","/app/main.py"]
I run this container with the following:
docker build -t jenkins_test .
docker run --name jenkins_test_container -tid -p 5000:5000 -p 8080:8080 jenkins_test:latest
I am able to start flask and install Jenkins, however, when running, Jenkins is not running. curl localhost:8080 is not successful.
In the log output, I am able to see:
Correct java version found
* Starting Jenkins Automation Server jenkins [ OK ]
However, it's still not running.
I can ssh into the container and manually run sudo /etc/init.d/jenkins start to start it, but I want it to start on docker run or docker build.
I have also tried putting sudo /etc/init.d/jenkins start in the CMD portion of the Docker file:
CMD python3 /app/main.py; sudo /etc/init.d/jenkins start
With this, I am able to curl Flask, but still not Jenkins.
How can I get Jenkins to start automatically?
You have some points that you need to be aware of:
No need to use sudo as the default user is root already.
In order to run multiple service in the same container you need to use any kind of service manager like Supervisord. Jenkins is not running because the CMD is the main entry point for your container so only flask should be running. Check the following link in order to know how to start multiple service in docker.
RUN will be executed only during the build process unlike CMD which will be executed each time you start a container from that image.
Combine all the RUN lines together as possible in order to minimize the build layers which lead to a smaller docker image.
Regarding the usage of this:
CMD python3 /app/main.py; sudo /etc/init.d/jenkins start
It does not work for you because this command python3 /app/main.py is not running as a background process so this command sudo /etc/init.d/jenkins start wont run until the previous command is done.
I was only able to get this to work by starting Jenkins in the CMD portion, but needed to start Jenkins before Flask since Flask would continuously run and the next command would never execute:
Did not work:
CMD python3 /app/main.py; sudo /etc/init.d/jenkins start
This did work:
CMD sudo /etc/init.d/jenkins start; python3 /app/main.py
EDIT:
I believe putting it in the RUN portion would not work because container would build but not save the any running services. I'm not sure if containers can be saved and loaded with running processes like that but I might be wrong. Would appreciate clarification if so.
It seems like a thing that should be in RUN so if anyone knows why that didn't work or some best practices, would also appreciate the info.

uwsgi-nginx in docker not works

I have Dockerfile like:
FROM python:3.6.5-jessie
MAINTAINER twitter myname
RUN apt-get update
RUN apt-get install -y git
RUN apt-get install -y nginx
RUN pip install --upgrade pip
RUN git clone https://github.com/hongmingu/requirements
RUN pip install -r /requirements/requirements_django.txt
RUN apt-get install -y vim
RUN mkdir -p /uwsgi_log
RUN git clone https://github.com/hongmingu/smaple_django
RUN apt-get install -y nginx
COPY ./nginx.conf /etc/nginx/nginx.conf
COPY ./uwsgi.ini /uwsgi.ini # it runs in daemonized mode
# These files are just setting files. nginx get request at port 8000 and uwsgi runs django project.
RUN uwsgi --ini /uwsgi.ini
RUN service nginx restart
CMD ["python3"]
I think these 2 lines not work:
RUN uwsgi --ini /uwsgi.ini
RUN service nginx restart
Because When I build it and run it with linux command: sudo docker run --rm -it -p 8080:8000 hongmingu/smaple:0.1 /bin/bash my 127.0.0.1:8080 does not work. But, When I attach container and type command manually like, uwsgi --ini /uwsgi.ini and service nginx restart, It works well.
So, Is it impossible to run uwsgi, nginx in Dockerfile?
I want to do it so that I hope I don't need to run uwsgi and nginx manually.
Where did I make fault? Is there any good way to do this?
This docker image(hongmingu/smaple:0.1) is here: https://cloud.docker.com/u/hongmingu/repository/docker/hongmingu/smaple
You misunderstood the RUN instruction
The RUN instruction will execute any commands in a new layer on top of
the current image and commit the results
It's used to build your image, it is not docker run which executes the command in the container.
The solutions involves to execute those 2 lines in the CMD or ENTRYPOINT with a shell script. uwsgi has also to be daemonized. Checkout this image https://github.com/tiangolo/uwsgi-nginx-docker

Build and run container but there is no container

I have a dockerfile look like this
FROM ubuntu
MAINTAINER abc <abc.yur#gmail.com>
RUN apt-get update
RUN apt-get install nano
RUN apt-get install -y software-properties-common python-software-properties
RUN add-apt-repository ppa:longsleep/golang-backports
RUN apt-get update
RUN apt-get -y install golang-go git
RUN mkdir /work
ENV GOPATH=/work
RUN go get github.com/abc/golang
RUN go build github.com/abc/golang
CMD /golang -addr $ADDR -workers $WORKERS
So I want to build and run container but after the building (docker build .) I can not run this container. So when I am running docker ps -a or docker ps there is not container to run
docker build .
This creates the image and not a container. You need to use
docker images
To get the list of images.
docker ps will show when you run a container using something like below
docker run -d <image>

adding a command docker image

I have built an image using these steps:
download adminer package
wget https://www.adminer.org/static/download/4.2.4/adminer-4.2.4-en.php
mv adminer-4.2.4-en.php adminer.php
create docker file
vi dockerfile
FROM ubuntu
RUN apt-get -y install apache2 php5 php5-curl php5-cli php5-mysql php5-gd mysql-client mysql-server
RUN apt-get -y install postgresql postgresql-contrib
RUN apt-get -y install php5-pgsql
COPY adminer.php /var/www/html/
RUN chmod -R 777 /var/www/html/
build and run
docker build -t shantanuo/adminer1 .
docker run -i -t --rm -p 80:80 --name adminer1 shantanuo/adminer1
I need to run this command to start apache once I am inside the container.
sudo service apache2 start
How do I include this command in the dockerfile? (Build failed after adding CMD for this purpose.)
Is there any other (better) way of installing adminer.php package?
Is it possible to reduce the size of this image?
What you do is opening an interactive bash session and try to start a server.
It would be better if you started your same image in detached mode (-d) instead of -it, and let apache runs.
For that, as commented, you need to start FROM httpd:2.4 which:
has a Dockerfile starting by default apache
has a httpd-foreground scripts launching apache server in foreground.
Even better would be to use a PHP docker image:
FROM php:5.6-apache
That way, you don't even have to install apache or php. You just copy your php application.
Then, if you need to, you can still open a bash session with:
docker exec -it <yourContainer> bash

Resources