I am trying to build a basic image and execute the container for Python Django web application. I have executed the below steps but when i try to run the container it throws an error message stating python3.8 executable not found. Could you please let me know if i am missing anything here. As when i try to check within the container i can see they python executable present
[root#fed32 ~]# buildah from fedora
[root#fed32 ~]# buildah run fedora-working-container -- dnf -y install python3.8
[root#fed32 ~]# buildah run fedora-working-container -- dnf -y install pip
[root#fed32 ~]# buildah run fedora-working-container -- pip install Django
[root#fed32 ~]# buildah run fedora-working-container -- mkdir -p /home/admin/Django_Projects
[root#fed32 ~]# buildah config --workingdir /home/admin/Django_Projects fedora-working-container
[root#fed32 ~]# buildah run fedora-working-container -- django-admin startproject mysite
[root#fed32 ~]# buildah config --workingdir /home/admin/Django_Projects/mysite fedora-working-container
[root#fed32 ~]# buildah config --env PATH=$PATH:/usr/bin/python3.8 fedora-working-container
[root#fed32 ~]# buildah config --cmd '["/usr/bin/python3.8", "manage.py", "runserver"]' fedora-working-container
[root#fed32 ~]# buildah config --port 8000 fedora-working-container
[root#fed32 ~]# buildah commit fedora-working-container hellodjango
Error -
[root#fed32 ~]# podman run -dt -p 8000:8000 localhost/hellodjango
Error: executable file `[/usr/bin/python3.8,` not found in $PATH: No such file or directory: OCI runtime command not found error
[root#fed32 ~]# buildah run fedora-working-container -- /bin/bash
[root#f283758d9ad2 Django_Projects]#
[root#f283758d9ad2 Django_Projects]# whereis python3.8
python3: /usr/bin/python3.8 /usr/bin/python3 /usr/lib/python3.8 /usr/lib64/python3.8 /usr/local/lib/python3.8 /usr/include/python3.8
[root#f283758d9ad2 Django_Projects]# ls -ltr /usr/bin/python3.8
-rwxr-xr-x. 1 root root 15536 Aug 13 11:53 /usr/bin/python3.8
[root#f283758d9ad2 Django_Projects]# echo $PATH
/root/.local/bin:/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/bin/python3.8
There was a syntax issue on how to pass cmd parameters. I was able to resolve the issue by modifying my cmd as below.
Before -
[root#fed32 ~]# buildah config --cmd '["/usr/bin/python3.8", "manage.py", "runserver"]' fedora-working-container
After -
[root#fed32 ~]# buildah config --cmd '"/usr/bin/python3.8" "manage.py" "runserver"' fedora-working-container
Related
i just have push my Symfony 5.4 application in my company server with Gitlab-ci and docker.
I have a Dokcerfile in the root avec my projet:
FROM php:7.4-apache
ENV APACHE_DOCUMENT_ROOT /var/www/html/public
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
COPY . /var/www/html/
RUN apt-get update \
&& apt-get install -y --no-install-recommends locales apt-utils git libicu-dev g++ libpng-dev libxml2-dev libzip-dev libonig-dev libxslt-dev;
RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \
echo "fr_FR.UTF-8 UTF-8" >> /etc/locale.gen && \
locale-gen
# INSTALL COMPOSER
RUN curl -sSk https://getcomposer.org/installer | php -- --disable-tls && \
mv composer.phar /usr/local/bin/composer
# INSTALL EXTENSION PHP
RUN docker-php-ext-configure intl
RUN docker-php-ext-install pdo pdo_mysql gd opcache intl zip calendar dom mbstring zip gd xsl
RUN pecl install apcu && docker-php-ext-enable apcu
# INSTALL YARN
RUN apt-get update && apt-get install -y gnupg2
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update && apt-get install -y yarn
RUN apt update
RUN chown -R www-data:www-data /var/www/html
RUN a2enmod rewrite
RUN service apache2 restart
And i have this job on my gitlab pipeline:
deploy_image:
stage: deploy
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- cd /srv/docker/stacks/r-panda
- docker network disconnect --force r-panda_default traefik_app
- /usr/local/bin/docker-compose down
- /usr/local/bin/docker-compose pull
- /usr/local/bin/docker-compose up -d
- docker network connect r-panda_default traefik_app
after_script:
- docker exec r-panda_app yarn install
- docker exec r-panda_app yarn run build
- ls -al
environment:
name: dev
url: $SERVER_URL
variables:
DATABASE_URL: $DATABASE_URL
tags:
- deploy
And there is my docker-compose.yaml on the server who run the contener with the application:
version: '3.9'
services:
r-panda_app:
container_name: r-panda_app
image: panda
environment:
- DATABASE_URL="mysql://db_user:db_pass#bbd_server:3306/panda_bdd"
restart: always
labels:
- traefik.enable=true
- traefik.http.routers.router-r-panda.rule=Host(`r-panda.fr`)
- traefik.http.routers.router-r-panda.tls.certresolver=myresolver
- traefik.http.routers.router-r-panda.tls=true
With this config i have the following error: An exception occurred in the driver: SQLSTATE[HY000] [2002] No such file or directory
But if i change my config/packages/doctrine.yaml
This
doctrine:
dbal:
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
url: '%env(resolve:DATABASE_URL)%'
To this:
doctrine:
dbal:
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
url: 'the real path for the DATABASE_URL'
Everything works
I don't know what to do, can someone help me
With buildah I am trying to build a container
image that should only contain the program cowsay and its dependencies.
I am doing this on a Fedora 29 computer where I don't have root permissions. Instead of using a Dockerfile and the command buildah build-using-dockerfile (aka buildah bud) I would like to
Create an empty container.
Mount its file system.
Use /usr/bin/dnf on my host system to install packages directly into the file system under the mount point.
Create the container image from the file system.
The command buildah from scratch creates an empty container but when I try to mount the file system I get an error
[testuser#linux ~]$ container=$(buildah from scratch)
[testuser#linux ~]$ mnt=$(buildah mount $container)
cannot mount using driver overlay in rootless mode
ERRO[0000] exit status 1
[testuser#linux ~]$
Some more information
[testuser#linux ~]$ cat /etc/redhat-release
Fedora release 29 (Twenty Nine)
[testuser#linux ~]$ buildah --version
buildah version 1.6 (image-spec 1.0.0, runtime-spec 1.0.0)
[testuser#linux ~]$
What goes wrong? How can I build the container image from scratch as a non-root user?
Short story
buildah unshare is needed to create an unshare environment. That was missing which led to the error message
cannot mount using driver overlay in rootless mode .
To build the container image create the file build.sh with this content
container=$(buildah from scratch)
mnt=$(buildah mount $container)
LC_ALL=C dnf install --installroot $mnt --release 29 --setopt=install_weak_deps=False -q -y cowsay
LC_ALL=C dnf --installroot $mnt clean all
buildah umount $container
buildah commit $container cowsay-container1
Then run the script build.sh inside an unshare environment
[testuser#linux ~]$ buildah unshare bash build.sh
List all images to see the newly built container image
[testuser#linux ~]$ buildah images
IMAGE NAME IMAGE TAG IMAGE ID CREATED AT SIZE
localhost/cowsay-container1 latest 9d9b88a8d5f1 Feb 18, 2019 17:26 307 MB
[testuser#linux ~]$
To try out the the newly built container image run
[testuser#linux ~]$ podman run localhost/cowsay-container1 cowsay hello
_______
< hello >
-------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
[testuser#linux ~]$
The build.sh script could be improved by adding some buildah config commands to provide some metadata information (e.g. buildah config --created-by and buildah config --cmd).
Longer story
Instead of building the container image with the script build.sh, it is also possible to step into the unshare environment and run build commands manually.
[testuser#linux ~]$ cat /etc/redhat-release
Fedora release 29 (Twenty Nine)
[testuser#linux ~]$ buildah unshare
[root#linux ~]# container=$(buildah from scratch)
[root#linux ~]# mnt=$(buildah mount $container)
[root#linux ~]# LC_ALL=C dnf install --installroot $mnt --release 29 --setopt=install_weak_deps=False -q -y cowsay
warning: /home/testuser/.local/share/containers/storage/overlay/cc67b957fb78eebe6a861a8b69ef4728d0660a636645813224b6ba94fbc80ce0/merged/var/cache/dnf/updates-0b4cc238d1aa4ffe/packages/bash-4.4.23-6.fc29.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 429476b4: NOKEY
Importing GPG key 0x429476B4:
Userid : "Fedora 29 (29) <fedora-29#fedoraproject.org>"
Fingerprint: 5A03 B4DD 8254 ECA0 2FDA 1637 A20A A56B 4294 76B4
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-29-x86_64
[root#linux ~]# LC_ALL=C dnf --installroot $mnt clean all
33 files removed
[root#linux ~]# buildah umount $container
020ee8e3fb29274a306c441770d2458c732e84076cc0487ce6ea06ac957640d4
[root#linux ~]# buildah commit $container cowsay-container2
Getting image source signatures
Copying blob b3fbecd80150: 292.45 MiB / 292.45 MiB [========================] 2s
Copying config 8aa2ad2933ce: 263 B / 263 B [================================] 0s
Writing manifest to image destination
Storing signatures
8aa2ad2933ce33c8ed8b7551c4a3261177ebd811c9b813b40d5ea77536ac6ef5
[root#linux ~]# exit
exit
[testuser#linux ~]$ buildah images
IMAGE NAME IMAGE TAG IMAGE ID CREATED AT SIZE
localhost/cowsay-container1 latest 9d9b88a8d5f1 Feb 18, 2019 17:26 307 MB
localhost/cowsay-container2 latest 8aa2ad2933ce Feb 18, 2019 17:47 307 MB
[testuser#linux ~]$ podman run localhost/cowsay-container2 cowsay hello
_______
< hello >
-------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
[testuser#linux ~]$
I have a complex Dockerfile which install much more than just mysql-server so I cannot start from an existing mysql container.
When removing all the extra-stuff I get this Dockerfile
FROM ubuntu:latest
ENV MYSQL_ROOT_PASSWORD=root
ENV MYSQL_ROOT_USER=root
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get install -y apt-utils
RUN apt-get install -y mysql-server
RUN usermod -d /var/lib/mysql/ mysql
RUN service mysql start
Unfortunately, mysql does not want to start:
---> 57a66bd64c2c
Step 8/9 : RUN usermod -d /var/lib/mysql/ mysql
---> Running in 596df248c2e4
---> ee78442bcc56
Step 9/9 : RUN service mysql start
---> Running in 0d9e5803cf33
* Starting MySQL database server mysqld
...fail!
The command '/bin/sh -c service mysql start' returned a non-zero code: 1
What is my mistake?
Looks like you've removed the most important parts of your docker file. Here is the Official MySQL repo Docker file.
FROM oraclelinux:7-slim
ENV PACKAGE_URL https://repo.mysql.com/yum/mysql-8.0-community/docker/x86_64/mysql-community-server-minimal-8.0.2-0.1.dmr.el7.x86_64.rpm
# Install server
RUN rpmkeys --import http://repo.mysql.com/RPM-GPG-KEY-mysql \
&& yum install -y $PACKAGE_URL \
&& yum install -y libpwquality \
&& rm -rf /var/cache/yum/*
RUN mkdir /docker-entrypoint-initdb.d
VOLUME /var/lib/mysql
COPY docker-entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
EXPOSE 3306 33060
CMD ["mysqld"]
You need to include a proper source with correct version to pull the image from.
and expose right ports, separate out volumes for MySQL to run. your container maybe failing due to any of this. I'd say remove the MySQL part out of your dockerfile and run the rest of the container.
Use the official mySQL image and install it in separate container. and then you can connect the Database with other apps.
already installed mysql-server package but it doesn't work
Package mariadb-server-3:10.1.21-3.fc25.x86_64 is already installed, skipping.
Dependencies resolved.
Nothing to do.
Complete!
[root#localhost ~]# /etc/rc
rc0.d/ rc1.d/ rc2.d/ rc3.d/ rc4.d/ rc5.d/ rc6.d/ rc.d/
[root#localhost ~]# /etc/rc.d/init.d/mysqld start
-bash: /etc/rc.d/init.d/mysqld: No such file or directory
Fedora is using systemd so you should use systemctl for starting services:
systemctl start mysqld
I am trying to compose my custom Dockerfile for setting up Mysql 5.7.
As part of this I would like to set s3 backup as well.
But when I try to run/create the docker instance it fails
Here is the Dockerfile:
# Start with a base mysql:5.6 image
FROM mysql:5.7
MAINTAINER Ikenna N. Okpala <me#ikennaokpala.com>
USER root
# RUN locale-gen
ENV DEBIAN_FRONTEND noninteractive
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.en
ENV LC_ALL en_US.UTF-8
ENV PS_NGX_EXTRA_FLAGS --with-cc=/usr/bin/gcc --with-ld-opt=-static-libstdc++
# Add all base dependencies
RUN apt-get update -y
RUN apt-get install -y build-essential checkinstall
RUN apt-get install -y vim curl wget unzip
RUN apt-get install -y libfuse-dev libcurl4-openssl-dev mime-support automake libtool python-docutils libreadline-dev
RUN apt-get install -y pkg-config libssl-dev
RUN apt-get install -y git-core
RUN apt-get install -y man cron
RUN apt-get install -y libgmp-dev
RUN apt-get install -y zlib1g-dev
RUN apt-get install -y libxslt-dev
RUN apt-get install -y libxml2-dev
RUN apt-get install -y libpcre3 libpcre3-dev
RUN apt-get install -y freetds-dev
# RUN apt-get install -y openjdk-7-jdk
RUN apt-get install -y software-properties-common
RUN mkdir -p /mnt/s3b
RUN sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/my.cnf
RUN cd ~/
RUN /bin/bash -l -c "wget https://github.com/s3fs-fuse/s3fs-fuse/archive/master.zip"
RUN unzip master.zip
RUN cd s3fs-fuse-master/ && ./autogen.sh && ./configure --prefix=/usr --with-openssl && make && make install
ADD templates/setup.sh /root/setup.sh
RUN chmod +x /root/setup.sh
ADD templates/backup-cron /etc/cron.d/backup-cron
RUN chmod 0644 /etc/cron.d/backup-cron
RUN cron
# RUN chmod +x /root/backup-cron
EXPOSE 3306
CMD ["/bin/bash", "-l", "-c", "/root/setup.sh"]
Here is the setup.sh file
#!/bin/bash
export MYSQL_HOST_IP=`awk 'NR==1 {print $1}' /etc/hosts`
set -e
set -x
# NOW=$(date +"%Y-%m-%d-%H%M")
# DUMP_FILE="/dumps/dump.sql"
echo $AWS_S3 >> ~/.passwd-s3fs && cp ~/.passwd-s3fs /etc/passwd-s3fs
chmod 600 ~/.passwd-s3fs
chmod 640 /etc/passwd-s3fs
mysql -h$MYSQL_HOST_IP -uroot -p$MYSQL_ROOT_PASSWORD -e "DROP DATABASE IF EXISTS $MYSQL_DATABASE; CREATE USER '$MYSQL_USER'#'localhost' IDENTIFIED BY '$MYSQL_PASSWORD'; CREATE DATABASE $MYSQL_DATABASE; GRANT ALL ON $MYSQL_DATABASE.* TO '$MYSQL_USER'#'localhost'; FLUSH PRIVILEGES;"
Here is the docker run command:
docker run --name=mysql-s3 --env MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} --env MYSQL_USER=${MYSQL_USER} --env MYSQL_PASSWORD=${MYSQL_PASSWORD} --env MYSQL_DATABASE=${MYSQL_DATABASE} --env AWS_S3=${AWS_S3} --detach --publish 3306:3306 --volume=/vagrant/scripts/dumps/:/dumps/ --cap-add mknod --cap-add sys_admin --device=/dev/fuse --privileged mysql-s3
This approach seems too complicated using fuse and modifying the base mysql container. I would suggest that you just stick with the base MYSQL and write a script that you run in a separate container that does a MYSQL dump to a text file and then copies that text file to S3 with the AWS CLI.