xxxxxxxxxx
docker run -d --rm --name my_container -p <Exposed_port>:<container_port> -v <local_path>:<container_path> <image_name>
xxxxxxxxxx
docker run -d --rm --name my_container -p 8001:8001 my_container
make sure youre using the right ports
xxxxxxxxxx
# DOCS Docker run (basic usage)
-d :-d=false: Detached mode: Run container in the background, print new container id
-t : Allocate a pseudo-tty
-i : Keep STDIN open even if not attached
-p : publicPort:InsideDockerPort - 8456:443
--restart <always/no/on-failure/unless-stopped>
--name ContainerName
--mount type=bind,source=/route/to/path/in/host,target=/route/to/path/inside/docker
Example:
docker run -d -it --restart always --name ContainerName -p 8456:443 --mount type=bind,source=/home/example/path/logs,target=/app/logs imagename:latest
xxxxxxxxxx
docker run --name <containerName> -p <EXPOSE-PORT>:<LOCAL-PORT> <IMAGE-NAME>
xxxxxxxxxx
RUN apt-get update \
&& apt-get install apt-transport-https ca-certificates \
&& echo "deb https://apt.dockerproject.org/repo debian-jessie main" > /etc/apt/sources.list.d/docker.list \
&& apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D \
&& apt-get update \
&& apt-get install -y docker-engine
xxxxxxxxxx
import docker
def run_docker_command(command):
client = docker.from_env() # Create Docker client
result = None
try:
result = client.api.exec_create(
container='your_container_id', # Replace with container ID
cmd=command, # Specify the Docker command to run
stdout=True,
stderr=True
)
# Start the Docker command
response = client.api.exec_start(exec_id=result['Id'])
# Get the output of the Docker command
output = client.api.exec_inspect(exec_id=result['Id'])
# Print the output
print(output)
except docker.errors.APIError as e:
print(f'Error executing Docker command: {e}')
run_docker_command('docker ps') # Replace with the Docker command you want to run