Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] authored and [email protected] committed Dec 24, 2023
0 parents commit ef8508e
Show file tree
Hide file tree
Showing 16 changed files with 671 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MODULAR_AUTH_KEY=mut_axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxf
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# ignore all . files and . folders
.*
!.env
!.gitignore

# Ignore some folders and all the files inside them
/tries
/Projects
191 changes: 191 additions & 0 deletions Docker_commands/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
https://docs.docker.com/engine/install/linux-postinstall/
Pre. Add user to the docker group
```bash
sudo usermod -aG docker $USER
```
0. Start docker daemon
```bash
sudo systemctl is-active docker
sudo systemctl start docker
sudo systemctl is-active docker || sudo systemctl start docker
```
1. Create a docker image
```bash
sudo docker build -t getting-started -f Dockerfile.mojosdk .
# or the below to confirm the docker daemon is active before running the command
sudo systemctl start docker && sudo docker build -t getting-started -f Dockerfile.mojosdk .
```
2. Changing a tag of an image
```bash
docker tag mojo-sdk:latest mojo-sdk:0.6
```
2. Export an image
```bash
docker save -o <image_name>.tar <image_name>:<tag>
```
2. Import the image
```bash
docker load -i <image_name>.tar
```
2. list image names:
```bash
docker images
```
3. Access Container Shell
```bash
docker exec -it <container_name> /bin/bash
```
3. Execute a command inside the container
```bash
docker run --rm my-app-minimal
```

3. Create a docker container
```bash
sudo docker run docker_image
```
4. Rename a container
```bash
docker rename <container_tag> mojo
```
4. List running containers
```bash
docker ps -a
```
5. Stop a container
```bash
docker stop <container_tag>
```
6. Convert a container to an image
```bash
docker commit <container_tag> image_distribution/image_name:image_tag
```
6. Start a container
```bash
docker container start <container_name>
```
Volumes:
1. Create volume:
```bash
docker volume create <volume_name>
```
2. Run a container with a volume:
```bash
docker run -d -v host_or_docker_volume:docker_volume docker_image
# docker build -t mojo-sdk:r0.6 -f Dockerfile.mojosdk --no-cache .
# docker volume create --opt type=none --opt device=/home/hajsf/Dockers/mojoDocker/Projects --opt o=bind mojoProjects

# docker run -d --publish (or -dp) host_domain_and_port:docker_exposed_port --name docker_container --mount source=<volume_name>,target=<path_in_docker> docker_image:image_tag
```
3. See the volumes at the host machine:
```bash
sudo -i
cd /var/lib/docker/volumes/
```
3. Export volume
```bash
docker run --rm -v <volume_name>:/data -v /tmp:/backup alpine tar -czvf /backup/<volume_name>.tar.gz /data
```
3. Import volume
```bash
docker run --rm -v <volume_name>:/data -v /tmp:/backup alpine tar -xzvf /backup/<volume_name>.tar.gz -C /
```
4.Stop the Container:

```bash
docker container stop mojo-sdk
```
5. Remove the Container (while keeping its data):

```bash
docker container rm -v mojo-sdk
```



Docker Garbage Collector:
```bash
docker system df -v
```
1. Disk Usage by Docker:
To view disk usage by Docker:
```bash
docker system df
```
2. Docker Image Sizes:
To list all Docker images and their respective sizes:
```bash
docker images -a
```
3. Docker Container Sizes:
To display the size of running containers:
```bash
docker ps -s
```
4. Docker Volume Sizes:
To list Docker volumes and their sizes:
```bash
docker volume ls -q | xargs docker volume inspect --format '{{ .Name }}: {{ .Mountpoint }}'
```

Clean up all
```bash
docker system prune -a
```

Stopping and Removing Containers
1. Stop all running containers:
```bash
docker stop $(docker ps -aq)
```
2. Remove all stopped containers:
```bash
docker container prune -a
// or
docker rm $(docker ps -aq)
```
3. Remove specific container
```bash
docker container rm <container_id>
```

Removing Images
1. Remove specific image
```bash
$ docker image remove <IMAGE_ID>
```
1. Remove dangling (unused) images:
```bash
docker image prune -a
```

2. Remove all images (Use with caution, as this will delete all your local Docker images):
```bash
docker rmi $(docker images -aq)
```

3. Remove all images without a tag
```bash
docker rmi $(docker images -f "dangling=true" -q)
```

Cleaning Volumes
1. Remove unused volumes:
```bash
docker volume prune -a
```

Clearing Cache and Temporary Files
1. Clear all unused data (including containers, networks, volumes, and images not referenced by any container):
```bash
docker system prune -a
```

MNetworks Cleanup
1. Remove all networks:
```bash
docker network prune -a
```



84 changes: 84 additions & 0 deletions Dockerfile.mojosdk
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Use Ubuntu 24.04 as the base image
FROM ubuntu:24.04

# Set the environment variable to noninteractive mode
ENV DEBIAN_FRONTEND=noninteractive

# Set /app as the working directory
WORKDIR /app

# Copy the shell script and the .env file into the Docker image
COPY auth_script.sh .
COPY .env .

RUN apt-get update && \
# Install required dependencies
apt-get install -y \
python3 \
python3-venv \
gnupg \
git \
curl \
wget \
&& apt-get clean && rm -rf /var/lib/apt/lists/* \
# Download Modular setup requirements
&& set -eux; \
keyring_location=/usr/share/keyrings/modular-installer-archive-keyring.gpg \
&& curl -1sLf 'https://dl.modular.com/bBNWiLZX5igwHXeu/installer/gpg.0E4925737A3895AD.key' | gpg --dearmor >> ${keyring_location} \
&& curl -1sLf 'https://dl.modular.com/bBNWiLZX5igwHXeu/installer/config.deb.txt?distro=debian&codename=wheezy' > /etc/apt/sources.list.d/modular-installer.list \
&& apt-get update \
# Install Modular
&& apt-get install -y modular \
&& apt-get clean && rm -rf /var/lib/apt/lists/* \
&& echo 'export MODULAR_HOME="/root/.modular"' >> ~/.bashrc \
&& echo 'export PATH="/root/.modular/pkg/packages.modular.com_mojo/bin:$PATH"' >> ~/.bashrc \
&& /bin/bash -c "source ~/.bashrc" \
# Install Mojo Lang
&& modular clean \
&& chmod +x auth_script.sh \
&& ./auth_script.sh \
&& modular install mojo \
# Create a symbolic link that points from /usr/bin/python to /usr/bin/python3
&& ln -s /usr/bin/python3 /usr/bin/python \
# Clean ubrequired dependencies
&& apt-get remove -y \
gnupg \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& apt-get purge -y --auto-remove \
# Delete the files after you're done with them
&& rm auth_script.sh .env

# Expose port 80
EXPOSE 80

# Set the entrypoint and command to keep the container running
ENTRYPOINT ["tail"]
CMD ["-f", "/dev/null"]

# docker build -t mojo-sdk -f Dockerfile.mojosdk --no-cache .
# docker run -d --publish 3000:80 --volume ./Projects:/root --name mojo-sdk mojo-sdk

# docker volume create mojoProjects
# docker run -d -v mojoProjects:/root mojo-sdk

# [hajsf@archlinux mojoDocker]$ sudo -i
# [root@archlinux ~]# cd /var/lib/docker/volumes/
# [root@archlinux volumes]# ls
# backingFsBlockDev metadata.db mojoProjects

# docker run -d --publish 3000:80 --name mojo-sdk mojo-sdk

# docker container stop mojo-sdk

# Remove the container without removing its data
# docker container rm -v mojo-sdk

## Map Volume
# docker volume create mojoProjects

# docker build -t mojo-sdk:r0.6 -f Dockerfile.mojosdk --no-cache .
# docker volume create --opt type=none --opt device=/home/hajsf/Dockers/mojoDocker/Projects --opt o=bind mojoProjects

# docker run -d --publish 3000:80 --name mojo-sdk --mount source=mojoProjects,target=/app mojo-sdk:r0.6
Loading

0 comments on commit ef8508e

Please sign in to comment.