Docker compose work on linux environment but not windows environment - windows

I am using 2 environment for development one is a linux VM at home while another is the windows laptop at office. The dockerfile of angular environment work fine until a few days ago, it show the following error when I tried to start the docker container with docker compose on the laptop:
ng | /bin/sh: 1: sudo: not found
ng exited with code 127
However, the same issue does not occurs on my linux VM.
Dockerfile:
FROM node:12
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 && apt-get install -yq google-chrome-stable
RUN mkdir /app
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json package-lock.json /app/
RUN npm install
#RUN npm install -g #angular/cli
COPY . /app
EXPOSE 4200
CMD ng serve --host 0.0.0.0
docker-compose.yaml:
version: "3"
services:
dj:
container_name: dj
build: Backend
command: python manage.py runserver 0.0.0.0:80
volumes:
- ./Backend:/code
ports:
- "80:80"
ng:
container_name: ng
build: Frontend/SPort
volumes:
- ./Frontend/SPort:/app
ports:
- "4200:4200"

I think you want to fix the sh script in your Dockerfile
add this:
RUN apt-get update && apt-get install -y dos2unix && dos2unix /path/to/the/script
hope that will help since the error comes from CRLF characters in windows

Related

The command '/bin/sh -c yum install yum-utils' returned a non-zero code: 1

i am trying to setup laravel php setup using docker.
Is something wrong with the docker file or the network configurations !!!!
Using DockerFile:
FROM centos:7
# Install some must-haves
RUN yum -y install vim wget sendmail
RUN yum -y install libtool make automake autoconf nasm libpng-static
RUN yum -y install git
RUN git --version
# Install PHP 7.1 on CentOS
RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \
&& rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
RUN yum install yum-utils
RUN yum install epel-release
RUN yum-config-manager --enable remi-php73
RUN yum --enablerepo=remi-php73 -y install php php-bcmath php-cli php-common php-gd php-intl php-ldap php-mbstring \
php-mysqlnd php-pear php-soap php-xml php-xmlrpc php-zip php-fpm
RUN php -v
# Prepare PHP environment
COPY config/php/php-fpm.conf /etc/php-fpm.conf
COPY config/php/www.conf /etc/php-fpm.d/www.conf
COPY config/php/php.ini /usr/local/etc/php/php.ini
COPY config/php/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/bin/composer
RUN composer --version
# Install Node.js
RUN curl -sL https://rpm.nodesource.com/setup_7.x | bash -
RUN yum -y install nodejs
RUN yum list installed nodejs
RUN node -v
# Final update and clean up
RUN yum -y update --skip-broken
RUN yum clean all
# Define work directory
WORKDIR /var/www/laravel-boilerplate
# Expose ports
EXPOSE 9000
CMD ["php-fpm", "-F", "-O"]
# CMD ["/bin/sh", "-l", "-c", "php-fpm"]
# CMD ["php-fpm", "-F"]
Command which i had run to setup the instances are,
docker-compose up -d
any idea what went wrong?
Adding docker compose file
version: '2'
services:
mysql:
image: mysql:latest
volumes:
- "./data/db:/var/lib/mysql"
ports:
- "3306:3306"
restart: always
environment:
- MYSQL_ROOT_PASSWORD=test
- MYSQL_DATABASE=laravel_boilerplate
- MYSQL_USER=root
- MYSQL_PASSWORD=secret
laravel-env:
build: ./dockerfiles
depends_on:
- mysql
volumes:
- ".:/var/www/laravel-boilerplate"
- "./dockerfiles/config/php/php-fpm.conf:/etc/php-fpm.conf"
- "./dockerfiles/config/php/www.conf:/etc/php-fpm.d/www.conf"
- "./dockerfiles/config/php/php.ini:/usr/local/etc/php/php.ini"
- "./dockerfiles/config/php/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini"
nginx:
image: nginx:latest
depends_on:
- laravel-env
volumes:
- ".:/var/www/laravel-boilerplate"
- "./dockerfiles/config/nginx/default.conf:/etc/nginx/conf.d/default.conf"
ports:
- "80:80"
restart: always
Let me know if I missed anything!!!!
Is something has to get removed while building or is something had to deleted like cleanup, am pretty new setting up the code so. Your help is much appreciated.
Thanks folks.

Why is the "sail up" command not building my laravel docker containers?

I'm trying out Laravel Sail, as I've been successfully using Laradock for a few years and hoping to simplify my dev environment setup. I am on Windows 10 64, Docker Desktop 3.0 installed using WSL 2, and my Laravel app is running Laravel 8.20.1.
In my Laravel project, I've followed the Laravel Sail setup guide: I've run composer require laravel/sail --dev and php artisan sail:install, and I see the docker-compose.yml in my root directory.
But when I run ./vendor/bin/sail up I get this error:
./vendor/bin/sail: line 1: XSym: command not found
./vendor/bin/sail: line 2: 0024: command not found
./vendor/bin/sail: line 3: a81960381c7144e16cd1e768af147de3: command not found
./vendor/bin/sail: line 4: ../laravel/sail/bin/sail: No such file or directory
Update: I fixed the above through Qumber's help: removing /vendor/ and reinstalling. But now I get this error:
In GitBash I get this response:
Unsupported operating system [MINGW64_NT-10.0-19041]. Laravel Sail supports macOS, Linux, and Windows (WSL2).
If I try from Powershell now, I get:
/bin/bash: C:\Users\ssund\Source\steepdb\vendor\bin\/../laravel/sail/bin/sail: No such file or directory
-------------Requested attachments--------------------
docker-compose.yml:
# For more information: https://laravel.com/docs/sail
version: '3'
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.0
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.0/app
ports:
- '${APP_PORT:-80}:80'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
volumes:
- '.:/var/www/html'
networks:
- sail
depends_on:
- mysql
- redis
# - selenium
# selenium:
# image: 'selenium/standalone-chrome'
# volumes:
# - '/dev/shm:/dev/shm'
# networks:
# - sail
mysql:
image: 'mysql:8.0'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
volumes:
- 'sailmysql:/var/lib/mysql'
networks:
- sail
redis:
image: 'redis:alpine'
ports:
- '${FORWARD_REDIS_PORT:-6379}:6379'
volumes:
- 'sailredis:/data'
networks:
- sail
# memcached:
# image: 'memcached:alpine'
# ports:
# - '11211:11211'
# networks:
# - sail
mailhog:
image: 'mailhog/mailhog:latest'
ports:
- 1025:1025
- 8025:8025
networks:
- sail
networks:
sail:
driver: bridge
volumes:
sailmysql:
driver: local
sailredis:
driver: local
Dockerfile in \vendor\laravel\sail\runtimes\7.4:
FROM ubuntu:20.04
LABEL maintainer="Taylor Otwell"
ARG WWWGROUP
WORKDIR /var/www/html
ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update \
&& apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 \
&& mkdir -p ~/.gnupg \
&& chmod 600 ~/.gnupg \
&& echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf \
&& apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E5267A6C \
&& apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C300EE8C \
&& echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu focal main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
&& apt-get update \
&& apt-get install -y php7.4-cli php7.4-dev \
php7.4-pgsql php7.4-sqlite3 php7.4-gd \
php7.4-curl php7.4-memcached \
php7.4-imap php7.4-mysql php7.4-mbstring \
php7.4-xml php7.4-zip php7.4-bcmath php7.4-soap \
php7.4-intl php7.4-readline php7.4-pcov \
php7.4-msgpack php7.4-igbinary php7.4-ldap \
php7.4-redis \
&& php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
&& curl -sL https://deb.nodesource.com/setup_15.x | bash - \
&& apt-get install -y nodejs \
&& apt-get install -y mysql-client \
&& apt-get -y autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN setcap "cap_net_bind_service=+ep" /usr/bin/php7.4
RUN groupadd --force -g $WWWGROUP sail
RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 sail
COPY start-container /usr/local/bin/start-container
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY php.ini /etc/php/7.4/cli/conf.d/99-sail.ini
RUN chmod +x /usr/local/bin/start-container
EXPOSE 8000
ENTRYPOINT ["start-container"]
Ok there were multiple things that I needed to fix here.
#Qumber helped me initially by suggesting I wipe /vendor/ and run composer install/update again. That fixed the missing sail file that wasn't getting added for some reason.
I also had some permission-related issues, possibly due to running compose in WSL and then trying to run sail in Windows/GitBash (or vice versa).
The biggest issue was my misunderstanding about Docker WSL2 integration and that the sail command should be run from within WLS (coming from Laradock, I made some incorrect assumptions). I needed to have a linux distro installed (I chose Ubuntu 20.x) AND make sure it was set as the default, via running wsl -s . You can check which is currently default with wsl -l -v. For more detailed steps about this setup see https://learn.microsoft.com/en-us/windows/wsl/install-win10#step-4---download-the-linux-kernel-update-package.
Once I fixed the above, I was able to open Windows Terminal, create an Ubuntu tab, and run ./vendor/bin/sail up and it executed.
You need to install linux under windows first. Your answer is correct. Thanks :)
If you're like me who cloned a Laravel project from GitHub where none of the application's Composer dependencies are available including Sail, you'll need to run the following commands from the project directory. The following commands use a small Docker Container containing PHP and Composer to install the application's dependencies:
docker run --rm \
-u "$(id -u):$(id -g)" \
-v $(pwd):/var/www/html \
-w /var/www/html \
laravelsail/php81-composer:latest \
composer install --ignore-platform-reqs
Further information can be found on the Laravel documentation.
For me, this was a permissions issue. Running as sudo worked.
Using Win10 with WSL Ubuntu 20.04 LTS.
I was facing this problem on my Mac .This issue is due to permission
Solution for MAC
1: Pull down the  Apple menu and choose ‘System Preferences’
2: Choose “Security & Privacy” control panel
3: Now select the “Privacy” tab, then from the left-side menu select “Full Disk Access”
4:Click the lock icon in the lower left corner of the preference panel and authenticate with an admin level login
5: Now click the [+] plus button to add an application with full disk access
6:Navigate to the /Applications/Utilities/ folder and choose “Terminal” to grant Terminal with Full Disk Access privileges
7: Relaunch Terminal, the “Operation not permitted” error messages will be gone
After that you can install Laravel.
Solution for Windows 10
Find the sail file in the vendor folder: vendor/laravel/sail/bin/sail and change from this code:
Verify operating system is supported...
case "${UNAMEOUT}" in
Linux*) MACHINE=linux;;
Darwin*) MACHINE=mac;;
*) MACHINE="UNKNOWN"
esac
if [ "$MACHINE" == "UNKNOWN" ]; then
echo "Unsupported operating system [$(uname -s)]. Laravel Sail supports macOS, Linux, and Windows (WSL2)." >&2
exit 1
fi
to this:
# Verify operating system is supported...
#case "${UNAMEOUT}" in
# Linux*) MACHINE=linux;;
# Darwin*) MACHINE=mac;;
# *) MACHINE="UNKNOWN"
#esac
#
#if [ "$MACHINE" == "UNKNOWN" ]; then
# echo "Unsupported operating system [$(uname -s)]. Laravel Sail supports macOS, Linux, and Windows (WSL2)." >&2
#
# exit 1
#fi
then use GitBash to run commond
./vendor/bin/sail up
From Unsupported operating system Laravel 8 with Sail on Windows 10 (WSL2)
This may sound crazy, but I had the same issue.
I just did vendor/bin/sail up
Instead of .vendor/bin/sail up
And that worked!

Postgres installation on Docker Ruby Alpine

I'm trying to complete the setup for my Rails application, using Docker. For development I use docker-compose.yml, and for production just the Dockerfile, as I want to deploy using Dokku (which has no support for compose).
In development everything is running fine, I'm getting my containers (app, webpacker and postgres), but in production mode my postgres container is missing... and also Dokku can't deploy correctly. I tried many ways, but nothing seems to work :(
Dockerfile
FROM ruby:2.5.5-alpine
ARG PRECOMPILEASSETS
ENV NODE_OPTIONS "--max_old_space_size=4096"
ENV SECRET_KEY_BASE=foo
RUN apk add --update --no-cache \
build-base \
git \
postgresql-dev \
postgresql-client \
imagemagick \
nodejs-current \
yarn \
python2 \
tzdata \
file
RUN gem install bundler
# Install gems
RUN mkdir /gems
WORKDIR /gems
COPY Gemfile .
COPY Gemfile.lock .
RUN bundle install -j4 --retry 3 \
# Remove unneeded files (cached *.gem, *.o, *.c)
&& rm -rf /usr/local/bundle/cache/*.gem \
&& find /usr/local/bundle/gems/ -name "*.c" -delete \
&& find /usr/local/bundle/gems/ -name "*.o" -delete
RUN yarn install
ARG INSTALL_PATH=/beweeg
ENV INSTALL_PATH $INSTALL_PATH
WORKDIR $INSTALL_PATH
COPY . .
# Precompile assets (or not)
RUN docker/potential_asset_precompile.sh $PRECOMPILEASSETS
# Expose Puma port
EXPOSE 3000
CMD ["docker/startup.sh"]
docker-compose.yml
version: '3.0'
services:
db:
image: postgres:11-alpine
ports:
- 5433:5432
environment:
POSTGRES_PASSWORD: postgres
webpacker:
image: beweeg_development
command: bin/webpack-dev-server
volumes:
- .:/beweeg:cached
ports:
- 3035:3035
app:
image: beweeg_development
build:
context: .
args:
- PRECOMPILEASSETS=NO
links:
- db
- webpacker
ports:
- 3000:3000
volumes:
- .:/beweeg:cached
As you'll see using docker-compose makes no problem, but if I want to build and run as production (without compose), then I cannot get pg installed correctly.
Previously I was using a Ruby slim image, and then using the following command:
RUN apt-get update && apt-get install -y curl gnupg
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main" > /etc/apt/sources.list.d/pgdg.list
RUN curl -q https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
was working nicely... but in order to reduce my images sizes, I'd prefer to stay now with Alpine.
I'm quite a noob, so please forgive me if the answer seems obvious... And thanks in advance for your help!

How do I install composer in container of docker?

I am new at docker and docker-compose and I am developing a Laravel-project on docker and docker-compose with Laradock as following a tutorial(not sure whether It is a correct way or not to refer this situation though).
I want to install the composer in this environment to be able to use the composer command.
As a matter of fact, I wanted to do seeding to put data into DB that I made by php artisan make:migrate but this error appeared.
include(/var/www/laravel_practice/vendor/composer/../../database/seeds/AdminsTableSeeder.php): failed to open stream: No such file or directory
So I googled this script to find a solution that will solve the error then I found it.
It says, "Do composer dump-autoload and try seeding again", so I followed it then this error appeared.
bash: composer: command not found
Because I have not installed composer into docker-container.
My docker's condition is like this now.
・workspace
・mysql
・apache
・php-fpm
Since I have not installed the composer, I have to install it into docker-container to solve the problem, BUT I have no idea how to install it into docker-container.
So could anyone tell me how to install composer into docker-container?
Thank you.
here is the laradock/mysql/Dockerfile and laravelProject/docker-compose.yml.
ARG MYSQL_VERSION=5.7
FROM mysql:${MYSQL_VERSION}
LABEL maintainer="Mahmoud Zalt <mahmoud#zalt.me>"
#####################################
# Set Timezone
#####################################
ARG TZ=UTC
ENV TZ ${TZ}
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && chown -R mysql:root /var/lib/mysql/
COPY my.cnf /etc/mysql/conf.d/my.cnf
CMD ["mysqld"]
EXPOSE 3306
version: '2'
services:
db:
image: mysql:5.7
ports:
- "6603:3306"
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=true
- MYSQL_DATABASE=laravelProject
- LANG=C.UTF-8
volumes:
- db:/var/lib/mysql
command: mysqld --sql-mode=NO_ENGINE_SUBSTITUTION --character-set-server=utf8 --collation-server=utf8_unicode_ci
web:
image: arbiedev/php-nginx:7.1.8
ports:
- "8080:80"
volumes:
- ./www:/var/www
- ./nginx.conf:/etc/nginx/sites-enabled/default
volumes:
db:
You can build your own image and use it in your Docker compose file.
FROM php:7.2-alpine3.8
RUN apk update
RUN apk add bash
RUN apk add curl
# INSTALL COMPOSER
RUN curl -s https://getcomposer.org/installer | php
RUN alias composer='php composer.phar'
# INSTALL NGINX
RUN apk add nginx
I used the PHP alpine image as my base image because it's lightweight, so you might have to install other dependencies yourself. In your docker-compose file
web:
build: path/to/your/Dockerfile/directory
image: your-image-tag
ports:
- "8080:80"
volumes:
- ./www:/var/www
- ./nginx.conf:/etc/nginx/sites-enabled/default
You could do something like this:
FROM php:8.0.2-apache
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y mariadb-client libxml2-dev
RUN apt-get autoremove -y && apt-get autoclean
RUN docker-php-ext-install mysqli pdo pdo_mysql xml
COPY --from=composer /usr/bin/composer /usr/bin/composer
the argument COPY --from= should solve your problem.
FROM php:7.3-fpm-alpine
RUN docker-php-ext-install pdo pdo_mysql
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer
RUN apk update
RUN apk upgrade
RUN apk add bash
RUN alias composer='php /usr/bin/composer'

How to setup laravel with npm using docker-compose?

I have the next docker-compose.yml file
version: '2'
services:
# The Application
app:
build:
context: ./
dockerfile: app.dockerfile
working_dir: /var/www/html
volumes:
- ./giftmeabetterplanet:/var/www/html
environment:
- "DB_PORT=3306"
- "DB_HOST=database"
# The Web Server
web:
build:
context: ./
dockerfile: web.dockerfile
working_dir: /var/www/html
links:
- database:mysql
volumes_from:
- app
ports:
- 81:80
environment:
- "WEB_DOCUMENT_ROOT=/var/www/html/public"
# The Database
database:
image: mysql:5.6
volumes:
- dbdata:/var/lib/mysql
environment:
- "MYSQL_DATABASE=homestead"
- "MYSQL_USER=homestead"
- "MYSQL_PASSWORD=secret"
- "MYSQL_ROOT_PASSWORD=secret"
ports:
- "3306"
volumes:
dbdata:
I need to make NPM (node package manager) accessible somehow to build my JS and CSS files in 'web' container.
app.dockerfile
FROM php:7.0.4
RUN apt-get update && apt-get install -y libmcrypt-dev \
mysql-client libmagickwand-dev --no-install-recommends \
&& pecl install imagick \
&& docker-php-ext-enable imagick \
&& docker-php-ext-install mcrypt pdo_mysql
web.dockerfile
FROM webdevops/php-apache-dev:ubuntu-16.04
I've tried the next way by extending web.dockerfile
FROM orlandohohmeier/local-npm
FROM webdevops/php-apache-dev:ubuntu-16.04
But npm is not accessible from the command line in 'web' container. Maybe i don't understand some concepts but i just want to compile my stiles, javascript files and copy fonts from node-modules.
Best regards. Ivan
For PHP7.2 this is what I have in my php.dockerfile
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
RUN apt-get install -y nodejs
Add to the docker-compose file
npm:
image: node:14
working_dir: /var/www/my_shiny_project
entrypoint: ["npm"]
volumes:
- "./www/:/var/www/my_shiny_project"
Usage:
docker-compose run --rm npm install
Don't forget to check the paths in both working_dir and volumes
Try adding this to your web.dockerfile.
RUN apt-get install -y nodejs npm
And then build your containers and try running node or npm within the web container
docker-compose run web bash
Follow this tutorial: https://medium.com/#wiwatSrt/laravel-development-environment-in-docker-containers-7b173f62f372
When docker-compose is set up, run command:
docker-compose run --rm nodejs npm install

Resources