Skip to content

Instantly share code, notes, and snippets.

@mudassaralichouhan
Last active September 30, 2024 00:46
Show Gist options
  • Save mudassaralichouhan/8997c4ac014711184536df3b5c50752a to your computer and use it in GitHub Desktop.
Save mudassaralichouhan/8997c4ac014711184536df3b5c50752a to your computer and use it in GitHub Desktop.
docker run --rm -v $(pwd):/app -w /app php php artisan serve
docker run --rm -v $(pwd):/app composer install
https://docs.docker.com/engine/reference/commandline/container_ls/
docker container ls --all
docker rm -vf $(docker ps -aq)
docker kill $(docker ps -q)
docker kill <container_id>
docker rm <container_id_or_name>
To start the container: docker start mysql-container
To stop the container: docker stop mysql-container
To remove the container: docker rm mysql-container
docker exec -it mysql-container mysql -u root -p
docker run -d --name phpmyadmin-container -e PMA_HOST=mysql-container -p 8080:80 phpmyadmin
docker run --name phpmyadmin-container -d -e PMA_ARBITRARY=1 -p 8080:80 phpmyadmin
docker run -d --name mysql-container -e MYSQL_ROOT_PASSWORD=123456 -e MYSQL_DATABASE=mydatabase -p 3306:3306 mysql
docker run --rm -it -v $(pwd):/src -w /src -e HOST=0.0.0.0 -p 8080:8080 node:lts bash -c "npm install && npm run dev"
docker run --name dev-mysql -e MYSQL_ROOT_PASSWORD=pass1234 -d mysql
docker run --name phpmyadmin -d --link dev-mysql -p 8080:80 phpmyadmin
sudo mkdir -p /opt/mysql
docker run -d \
--name asgard-mysql \
--network asgard \
-e MYSQL_ROOT_PASSWORD="OuPfme45oAM6m6S8lqy4PQfxlYFlCnmPzyaloZ5Zw=" \
-v /opt/mysql:/var/lib/mysql \
-p 3306:3306 \
mysql
docker run -d \
--name asgard-phpmyadmin \
--network asgard \
-e PMA_HOST=asgard-mysql \
-e PMA_USER=root \
-e PMA_PASSWORD=OuPfme45oAM6m6S8lqy4PQfxlYFlCnmPzyaloZ5Zw= \
-p 8080:80 \
phpmyadmin
@mudassaralichouhan
Copy link
Author

It looks like you're trying to start a container from an existing container ID (6721f18f3f9b), but docker run is used to create and start new containers from an image, not from an existing container. Since docker run is looking for an image named 6721f18f3f9b, it fails because this is actually a container ID, not an image name.

To expose the SSH port of an existing container, you'll need to commit the current state of the container to a new image and then run that image with the correct port mapping. Here’s how you can proceed:

Step 1: Commit the existing container to a new image

First, commit the current container state to a new image:

sudo docker commit 6721f18f3f9b new-image-name

Replace new-image-name with a name you’d like for your new image.

Step 2: Run the new image with the port mapping

Now, run the new image with the desired port binding:

sudo docker run -d -p 2222:22 new-image-name

Alternative Approach: Create a New Container with Port Mapping

If the above approach doesn’t work or if you prefer starting over, you can stop and remove the existing container, then create a new one from the original image with the correct port mapping:

  1. Stop and remove the existing container:

    sudo docker stop 6721f18f3f9b
    sudo docker rm 6721f18f3f9b
  2. Run a new container from the original image (assuming you know the original image name):

    sudo docker run -d -p 2222:22 original-image-name

Replace original-image-name with the name of the image that was used to create the container.

Let me know if you need further help!

@mudassaralichouhan
Copy link
Author

mudassaralichouhan commented Sep 20, 2024

docker run -it --rm --name zatca_api_server_container ubuntu:latest /bin/bash
docker exec -it zatca_api_server_container /bin/bash
docker start zatca_api_server_container
systemctl restart docker.service
apt install ruby-build ruby-build zip git php wget nano jq default-jdk
docker run -it -p 8080:80 -p 2222:22 --name zatca_api_server_container ubuntu:latest /bin/bash
apt-get install -y openssh-server
sudo nano /etc/ssh/sshd_config
PermitRootLogin yes
service ssh start
passwd
service ssh restart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment