Running Docker Creates Vite Issues - docker

web_services-api-1 | Watching for file changes with StatReloader
web_services-frontend-1 | node:fs:1395
web_services-frontend-1 | handleErrorFromBinding(ctx);
web_services-frontend-1 | ^
web_services-frontend-1 |
web_services-frontend-1 | Error: EACCES: permission denied, mkdir '/frontend/node_modules/.vite/deps_temp'
web_services-frontend-1 | at Object.mkdirSync (node:fs:1395:3)
web_services-frontend-1 | at runOptimizeDeps (file:///frontend/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:42704:14)
web_services-frontend-1 | at Timeout._onTimeout (file:///frontend/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:42112:58)
web_services-frontend-1 | at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
web_services-frontend-1 | errno: -13,
web_services-frontend-1 | syscall: 'mkdir',
web_services-frontend-1 | code: 'EACCES',
web_services-frontend-1 | path: '/frontend/node_modules/.vite/deps_temp'
web_services-frontend-1 | }
web_services-frontend-1 |
web_services-frontend-1 | Node.js v18.13.0
It has the frontend/node_modules/ folder with the appropriate permissions but it lacks a .vite/deps_temp folder being created.
List of permissions:
drwxrwxrwx 312 arundeep docker 12288 Jan 23 14:24 node_modules
drwxrwxr-x 6 arundeep docker 4096 Jan 22 21:14 vite
drwxrwxr-x 2 arundeep docker 4096 Jan 22 21:14 bin
-rw-rw-r-- 1 arundeep docker 3913 Jan 22 21:14 client.d.ts
drwxrwxr-x 5 arundeep docker 4096 Jan 22 21:14 dist
-rw-rw-r-- 1 arundeep docker 997 Jan 22 21:14 index.cjs
-rw-rw-r-- 1 arundeep docker 168938 Jan 22 21:14 LICENSE.md
-rw-rw-r-- 1 arundeep docker 3980 Jan 22 21:14 package.json
-rw-rw-r-- 1 arundeep docker 1164 Jan 22 21:14 README.md
drwxrwxr-x 3 arundeep docker 4096 Jan 22 21:14 src
drwxrwxr-x 2 arundeep docker 4096 Jan 22 21:14 types

Related

How to mount volumes inside a container that is started from a bash script in Google Cloud Build?

I have a cloudbuild.yaml file that looks like this:
steps:
- name: 'gcr.io/cloud-builders/gsutil'
args: [ "-m", "rsync", "-r", "gs://${_BUCKET}/maven-repository", "/cache/.m2" ]
volumes:
- path: '/cache/.m2'
name: 'm2_cache'
- name: docker/compose:debian-1.29.2
entrypoint: bash
args:
- -c
- |
./test.sh
volumes:
- path: '/cache/.m2'
name: 'm2_cache'
timeout: 2700s
substitutions:
_BUCKET: 'my-bucket'
In the first step we download our maven settings.xml file from GCS. This file is crucial for subsequent build steps since it contain the username/password to our Artifact Registry Maven repository (I've simplified this example as we don't actually store the credential in the settings.xml as plain text). Without these credentials, our Maven build won't run. Normally the script that we call in the second step starts several docker containers and then run our maven tests. But I've replaced it with test.sh to easier show what the problem is. The test.sh file is shown below:
#!/bin/bash
echo "### [Host] Contents in /cache/.m2"
ls -la /cache/.m2
mkdir ~/test
echo "Johan" > ~/test/ikk.txt
echo "### [Host] Contents in ~/test"
ls -la ~/test
docker run --rm -v /cache/.m2:/cache/.m2 -v ~/test:/root/test -w /usr/src/somewhere ubuntu bash -c 'echo "### [Docker] Contents in /cache/.m2" && ls -la /cache/.m2 && echo "### [Docker] Contents in /root/test" && ls -la /root/test'
I.e. we try to mount two volumes to the ubuntu container that we start in the test.sh file. I list the contents in two directors both outside (### [Host]) and inside (### [Docker]) the ubuntu container. Here's the relevant output of running this in cloud build:
### [Host] Contents in /cache/.m2
total 16
drwxr-xr-x 2 root root 4096 Sep 15 08:55 .
drwxr-xr-x 3 root root 4096 Sep 15 08:55 ..
-rw-r--r-- 1 root root 8063 Sep 13 11:03 settings.xml
### [Host] Contents in ~/test
total 12
drwxr-xr-x 2 root root 4096 Sep 15 08:55 .
drwxr-xr-x 6 root root 4096 Sep 15 08:55 ..
-rw-r--r-- 1 root root 6 Sep 15 08:55 ikk.txt
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
Digest: sha256:20fa2d7bb4de7723f542be5923b06c4d704370f0390e4ae9e1c833c8785644c1
Status: Downloaded newer image for ubuntu:latest
### [Docker] Contents in /cache/.m2
total 8
drwxr-xr-x 2 root root 4096 Sep 15 08:55 .
drwxr-xr-x 3 root root 4096 Sep 15 08:55 ..
### [Docker] Contents in /root/test
total 8
drwxr-xr-x 2 root root 4096 Sep 15 08:55 .
drwx------ 1 root root 4096 Sep 15 08:55 ..
As you can see, the volume mounts doesn't seem to work when I run the ubuntu container from the test.sh file in cloud build (since the contents of /root/test and /cache/.m2 are empty).
Running the test.sh locally on my machine yields the expected outcome:
### [Host] Contents in /cache/.m2
total 40
drwxr-xr-x 7 johan staff 224 Mar 15 2022 .
drwxr-x---+ 87 johan staff 2784 Sep 15 10:58 ..
-rw-r--r-- 1 johan staff 2344 Sep 14 11:37 copy_reference_file.log
drwxr-xr-x 221 johan staff 7072 Sep 14 10:52 repository
-rw-r--r-- 1 johan staff 327 Nov 24 2021 settings-docker.xml
-rw-r--r--# 1 johan staff 9842 Mar 15 2022 settings.xml
drwxr-xr-x 3 johan staff 96 Nov 19 2021 wrapper
### [Host] Contents in ~/test
total 8
drwxr-xr-x# 3 johan staff 96 Sep 15 10:53 .
drwxr-xr-x# 135 johan staff 4320 Sep 15 10:49 ..
-rw-r--r-- 1 johan staff 6 Sep 15 10:58 ikk.txt
### [Docker] Contents in /cache/.m2
total 24
drwxr-xr-x 7 root root 224 Mar 15 2022 .
drwxr-xr-x 3 root root 4096 Sep 15 08:58 ..
-rw-r--r-- 1 root root 2344 Sep 14 09:37 copy_reference_file.log
drwxr-xr-x 221 root root 7072 Sep 14 08:52 repository
-rw-r--r-- 1 root root 327 Nov 24 2021 settings-docker.xml
-rw-r--r-- 1 root root 9842 Mar 15 2022 settings.xml
drwxr-xr-x 3 root root 96 Nov 19 2021 wrapper
### [Docker] Contents in /root/test
total 8
drwxr-xr-x 3 root root 96 Sep 15 08:53 .
drwx------ 1 root root 4096 Sep 15 08:58 ..
-rw-r--r-- 1 root root 6 Sep 15 08:58 ikk.txt
Here you can see that the volumes are mounted correctly and I can access the files inside the ubuntu container.
How can I mount volumes inside a container in cloud build?

how to run a dbt container from command line with volumes

was trying to make a quick dbt container:
docker pull xemuliam/dbt
docker run -d --name dbt \
-p 8085:8085 \
-v /home/mypath/app:/usr/app \
xemuliam/dbt:latest
that didn't work, so i tried to inspect and saw the binding was rprivate, so i changed it to:
docker run -d --name dbt \
-p 8085:8085 \
-v /home/mypath/app:/usr/app,rshared:rshared \
xemuliam/dbt:latest
the issue is that /home/mypath/app ends up being empty, and if i go inside the container it has in the working directory of /usr/app:
drwxr-xr-x 15 root root 4096 Apr 29 12:24 .
drwxr-xr-x 1 root root 4096 Jun 21 20:14 ..
-rw-rw-r-- 1 root root 4895 Apr 28 16:54 ARCHITECTURE.md
-rwxrwxr-x 1 root root 16732 Apr 28 16:54 CHANGELOG.md
-rw-rw-r-- 1 root root 18081 Apr 28 16:54 CONTRIBUTING.md
-rw-rw-r-- 1 root root 2239 Apr 28 16:54 Dockerfile.test
-rw-rw-r-- 1 root root 11344 Apr 28 16:54 License.md
-rw-rw-r-- 1 root root 3271 Apr 28 16:54 Makefile
-rw-rw-r-- 1 root root 2365 Apr 28 16:54 README.md
drwxrwxr-x 5 root root 4096 Apr 28 16:54 core
drwxrwxr-x 4 root root 4096 Apr 29 12:23 dbt-core-1.1.0
-rw-rw-r-- 1 root root 205 Apr 28 16:54 dev-requirements.txt
drwxrwxr-x 2 root root 4096 Apr 28 16:54 docker
-rw-rw-r-- 1 root root 777 Apr 28 16:54 docker-compose.yml
drwxrwxr-x 3 root root 4096 Apr 28 16:54 docs
-rw-rw-r-- 1 root root 51 Apr 28 16:54 editable-requirements.txt
drwxrwxr-x 2 root root 4096 Apr 28 16:54 etc
drwxrwxr-x 3 root root 4096 Apr 28 16:54 events
-rw-rw-r-- 1 root root 65 Apr 28 16:54 mypy.ini
drwxrwxr-x 8 root root 4096 Apr 28 16:54 performance
drwxrwxr-x 6 root root 4096 Apr 28 16:54 plugins
-rw-r--r-- 1 root root 95 Apr 29 12:23 plugins.txt
-rw-rw-r-- 1 root root 242 Apr 28 16:54 pytest.ini
-rw-rw-r-- 1 root root 26 Apr 28 16:54 requirements.txt
drwxrwxr-x 2 root root 4096 Apr 28 16:54 scripts
drwxrwxr-x 5 root root 4096 Apr 28 16:54 test
drwxrwxr-x 7 root root 4096 Apr 28 16:54 tests
drwxrwxr-x 10 root root 4096 Apr 28 16:54 third-party-stubs
-rw-rw-r-- 1 root root 798 Apr 28 16:54 tox.ini
drwxr-xr-x 2 root root 4096 Apr 29 12:24 wheels
in my postgres db i am able to do a volume like this and it works:
-v /home/mypath/data:/var/lib/postgresql/data
i would like to access that stuff on the host so i can play around with editing it.
this is probably the worst way to get this done, so i would appreciate a better answer - but my solution:
step 1: pull image
$ podman pull xemuliam/dbt
step 2: create a container through cli instead of dockerfile
$ podman run -d --name db_dbt \
-p 8085:8085 \
-v /home/myusr/dbt_test/_official:/home/dbt_test/_official \
xemuliam/dbt:latest
step 3: copy files from /usr/app to /home/dbt_test/_official
$ cp -R /usr/app/* /home/dbt_test/_official
exit
$ podman stop db_dbt && podman rm db_dbt
step 4: copy files on the host
$ mkdir /home/myusr/dbt_test/app1
$ cp -R /home/myusr/dbt_test/_official/* /home/myusr/dbt_test/app1/
step 5: create a new volume
$ podman run -d --name db_dbt \
-p 8085:8085 \
-v /home/myusr/dbt_test/app1/:/usr/app/ \
xemuliam/dbt:latest
i really dont like this roundabout way, but now i am able to edit from the host and see what the container does.

The rights to the laravel-project directory are not setting

php Dockerfile:
FROM php:8-fpm-alpine
WORKDIR /var/www/project
# Install dependencies
RUN apk update && apk add zip git libzip-dev postgresql-client postgresql-dev
## Install extensions
RUN docker-php-ext-install opcache zip pdo_pgsql
RUN apk add --no-cache bash
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Copy existing application directory permissions
COPY --chown=www-data:www-data . /var/www/project
docker-compose.yml:
version: '3'
services:
# NGINX - Service
nginx:
build:
context: .
dockerfile: docker-compose/nginx/Dockerfile
ports:
- "8080:80"
- "8143:443"
links:
- php-fpm
volumes:
- ./:/var/www/project
# PHP-FPM - Service
php-fpm:
build:
context: .
dockerfile: docker-compose/php/Dockerfile
volumes:
- ./:/var/www/project
ls -la project( sudo docker exec -it project_php-fpm_1 bash):
bash-5.1$ ls -la
total 416
drwxrwxr-x 16 1001 1001 4096 Jan 22 08:52 .
drwxr-xr-x 1 root root 4096 Jan 22 09:26 ..
-rw-rw-r-- 1 1001 1001 126 Nov 13 10:44 .editorconfig
-rw-rw-r-- 1 1001 1001 1499 Dec 30 12:04 .env
-rw-rw-r-- 1 1001 1001 1422 Nov 26 11:31 .env.example
drwxrwxr-x 8 1001 1001 4096 Jan 22 08:05 .git
-rw-rw-r-- 1 1001 1001 111 Nov 10 14:57 .gitattributes
-rw-rw-r-- 1 1001 1001 247 Dec 4 20:35 .gitignore
drwxrwxr-x 6 1001 1001 4096 Jan 22 09:26 .idea
-rw-rw-r-- 1 1001 1001 356 Nov 18 07:19 .phpunit.result.cache
-rw-rw-r-- 1 1001 1001 0 Nov 18 08:50 README.md
drwxrwxr-x 12 1001 1001 4096 Jan 6 19:56 app
-rwxr-xr-x 1 1001 1001 1686 Nov 10 14:57 artisan
drwxrwxr-x 3 1001 1001 4096 Nov 10 14:57 bootstrap
-rw-rw-r-- 1 1001 1001 1749 Dec 9 06:39 composer.json
-rw-rw-r-- 1 1001 1001 311695 Jan 11 06:54 composer.lock
drwxrwxr-x 2 1001 1001 4096 Jan 6 19:34 config
drwxrwxr-x 5 1001 1001 4096 Nov 10 14:57 database
drwxrwxr-x 4 1001 1001 4096 Jan 21 12:47 docker-compose
-rw-rw-r-- 1 1001 1001 435 Jan 22 08:52 docker-compose.yml
drwxrwxr-x 5 1001 1001 4096 Jan 11 06:54 frontend
-rw-rw-r-- 1 1001 1001 1202 Nov 10 14:57 phpunit.xml
drwxrwxr-x 5 1001 1001 4096 Jan 21 17:34 public
drwxrwxr-x 4 1001 1001 4096 Nov 23 11:53 resources
drwxrwxr-x 3 1001 1001 4096 Jan 11 06:54 routes
-rw-rw-r-- 1 1001 1001 563 Nov 10 14:57 server.php
drwxrwxrwx 5 1001 xfs 4096 Nov 16 12:00 storage
drwxrwxr-x 4 1001 1001 4096 Nov 17 20:31 tests
drwxrwxr-x 52 1001 1001 4096 Jan 11 06:23 vendor
Error:
The stream or file "/var/www/project/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied
how can this be fixed?

GitLab runner cannot write file

As shown below, I tried to write my public key into /root/.ssh/known_hosts in some a shared GitLab runner with the executor of docker using the alpine docker image.
Variable $HOST_FINGERPRINT is initialized which could be proven by the command echo $HOST_FINGERPRINT, but it just cannot be output to the known_hosts file for some reason.
Does anybody have any clue?
$ ls -al
total 32
drwxrwxrwx 2 root root 4096 Jul 11 00:15 .
drwxrwxrwx 8 root root 4096 Jul 11 00:15 ..
-rwxrwxrwx 1 root root 121 Jul 11 00:15 Dockerfile
-rwxrwxrwx 1 root root 183 Jul 11 00:15 known_hosts
$ echo $HOST_FINGERFRINT
xxxxxxxxx, xxxxxxx, ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBAG/dWuic73JmrfWPxJkKlW2xXFUJUGkoF2XnPZeVMUE+LF4VU9QXnukuTXFiKCZQGqrnK8UquqSRc3Z/MTBBdo=
$ echo $HOST_FINGERPRINT > known_hosts
$ echo $?
0
$ ls -l .
total 16
-rwxrwxrwx 1 root root 121 Jul 11 00:15 Dockerfile
-rwxrwxrwx 1 root root 1 Jul 11 00:15 known_hosts
$ echo $HOST_FINGERPRINT > known
$ echo $?
0
$ ls -l .
total 24
-rwxrwxrwx 1 root root 121 Jul 11 00:15 Dockerfile
-rw-r--r-- 1 root root 1 Jul 11 00:15 known
-rwxrwxrwx 1 root root 1 Jul 11 00:15 known_hosts

kitura docker error checking context: 'can't stat '/home/conor/workspace/UserInstruction/.build-ubuntu/checkouts''

I am unable to build the docker image which will be uploaded to DockerHub/AWS EC2, the folder is owned by root. The docker install is as directed on the official docker docs, the hello-world test runs without error. I am following the post here https://www.raywenderlich.com/1244870-deploying-kitura-with-docker-kubernetes-getting-started
The Swift/Kitura project builds and runs without error.
conor#lenovo:~/workspace/UserInstruction$ ls -la
total 56
drwxr-xr-x 7 conor conor 4096 Dec 11 16:15 .
drwxr-xr-x 7 conor conor 4096 Dec 11 09:52 ..
drwxr-xr-x 5 conor conor 4096 Dec 11 16:13 .build
drwxr-xr-x 5 root root 4096 Dec 11 16:17 .build-ubuntu
-rw-r--r-- 1 conor conor 950 Dec 11 16:16 Dockerfile
-rwxr-xr-x 1 conor conor 876 Dec 10 08:49 Dockerfile-tools
drwxr-xr-x 8 conor conor 4096 Dec 10 11:46 .git
-rw-r--r-- 1 conor conor 53 Dec 10 08:25 .gitignore
-rw-r--r-- 1 conor conor 4144 Dec 11 16:16 Package.resolved
-rw-r--r-- 1 conor conor 716 Dec 11 16:16 Package.swift
-rw-r--r-- 1 conor conor 50 Dec 10 08:25 README.md
drwxr-xr-x 3 conor conor 4096 Dec 10 08:25 Sources
drwxr-xr-x 3 conor conor 4096 Dec 10 08:25 Tests
root#lenovo:~# ls -la /home/conor/workspace/UserInstruction/.build-ubuntu/
total 284
drwxr-xr-x 5 root root 4096 Dec 11 16:17 .
drwxr-xr-x 7 conor conor 4096 Dec 11 16:15 ..
-rw-r--r-- 1 root root 142336 Dec 11 16:17 build.db
drwxr-x--- 17 root root 4096 Dec 11 16:16 checkouts
-rw-r--r-- 1 root root 5283 Dec 11 16:16 dependencies-state.json
-rw-r--r-- 1 root root 2 Dec 11 16:16 regenerate-token
lrwxrwxrwx 1 root root 28 Dec 11 16:17 release -> x86_64-unknown-linux/release
-rw-r--r-- 1 root root 114525 Dec 11 16:16 release.yaml
drwxr-x--- 17 root root 4096 Dec 11 16:16 repositories
drwxr-x--- 3 root root 4096 Dec 11 16:16 x86_64-unknown-linux
swift --version
Swift version 5.1 (swift-5.1.2-RELEASE)
Target: x86_64-unknown-linux-gnu
List of Commands Run
swift build
docker build -t user-instructions-build -f Dockerfile-tools .
docker run -v $PWD:/swift-project -w /swift-project user-instructions-build /swift-utils/tools-utils.sh build release
conor#lenovo:~/workspace/UserInstruction$ docker build -t user-instructions-run .
error checking context: 'can't stat '/home/conor/workspace/UserInstruction/.build-ubuntu/checkouts''.
ls /home/conor/workspace/UserInstruction/.build-ubuntu/
build.db checkouts dependencies-state.json regenerate-token release release.yaml repositories x86_64-unknown-linux
Dockerfile
FROM ibmcom/swift-ubuntu-runtime:4.1.0
MAINTAINER IBM Swift Engineering at IBM Cloud
LABEL Description="Template Dockerfile that extends the ibmcom/swift-ubuntu-runtime image."
# We can replace this port with what the user wants
EXPOSE 8080
# Default user if not provided
ARG bx_dev_user=root
ARG bx_dev_userid=1000
# Install system level packages
# RUN apt-get update && apt-get dist-upgrade -y
# Add utils files
ADD https://raw.githubusercontent.com/IBM-Swift/swift-ubuntu-docker/master/utils/run-utils.sh /swift-utils/run-utils.sh
ADD https://raw.githubusercontent.com/IBM-Swift/swift-ubuntu-docker/master/utils/common-utils.sh /swift-utils/common-utils.sh
RUN chmod -R 555 /swift-utils
# Create user if not root
RUN if [ $bx_dev_user != "root" ]; then useradd -ms /bin/bash -u $bx_dev_userid $bx_dev_user; fi
# Bundle application source & binaries
COPY . /swift-project
# Command to start Swift application
CMD [ "sh", "-c", "swift run" ]
Package.swift
// swift-tools-version:4.1.0
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
// 1
name: "UserInstruction",
dependencies: [
// 2
.package(url: "https://github.com/IBM-Swift/Kitura.git",
.upToNextMajor(from: "2.0.0")),
// 3
.package(url: "https://github.com/IBM-Swift/HeliumLogger.git",
.upToNextMajor(from: "1.0.0")),
// 4
.package(url: "https://github.com/IBM-Swift/Kitura-CouchDB.git",
.upToNextMajor(from: "3.0.0"))
],
//5
targets: [
.target(name: "UserInstruction",
dependencies: ["Kitura" , "HeliumLogger", "CouchDB"],
path: "Sources")
]
)
full output

Resources