Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Dockerfile for image Drakkar_ipfs update: 36161998
- #Use: docker run -d -p 5001:5001 -p 8080:8080 -p 8000:8000 -p 4001:4001 -v ipfsStorage:/root/.ipfs -v "$(pwd)":/var/www/html --name php_ipfs0 php-ipfs-combo4;
- FROM debian:bullseye-slim
- # Install necessary dependencies, including PHP
- RUN apt-get update && apt-get install -y \
- curl tar php \
- && echo "Dependencies installed."
- # Copy IPFS tarball from the host project directory into the container
- COPY go-ipfs_v0.14.0_linux-amd64.tar.gz /tmp/
- # Extracting IPFS version v0.14.0 tarball... previous downloading to the projectBlank folder
- RUN tar -xvzf /tmp/go-ipfs_v0.14.0_linux-amd64.tar.gz -C /tmp/ \
- && mv /tmp/go-ipfs/ipfs /usr/local/bin/ \
- && chmod +x /usr/local/bin/ipfs \
- && rm -rf /tmp/go-ipfs /tmp/go-ipfs_v0.14.0_linux-amd64.tar.gz
- # Expose the default IPFS API, Gateway, and PHP ports
- EXPOSE 5001
- EXPOSE 8080
- EXPOSE 8000
- EXPOSE 4001
- # Copy the start.sh script and make it executable
- COPY start.sh /start.sh
- RUN chmod +x /start.sh
- # Set working directory (for PHP server)
- WORKDIR /var/www/html
- # Run the script when the container starts
- CMD ["/start.sh"]
- Bash script
- #!/bin/bash
- #update: 36161998
- HOST_DOCKERFILE_PATH="$(pwd)/Dockerfile"
- HOST_START_SH_PATH="$(pwd)/start.sh"
- HOST_LOG_PATH="$(pwd)/startup_log.txt"
- CONTAINER_HOME_DOCKERFILE="/home/Dockerfile"
- CONTAINER_HOME_STARTUP="/home/start.sh"
- CONTAINER_HOME_LOG="/home/startup_log.txt"
- # Function to write logs to both the host log file and standard output
- log_message() {
- echo "$1" | tee -a "$HOST_LOG_PATH"
- }
- # Check if the volume ipfsStorage exists
- log_message "Checking if volume ipfsStorage exists..."
- if ! docker volume inspect ipfsStorage > /dev/null 2>&1; then
- log_message "Volume ipfsStorage does not exist. Creating it now..."
- docker volume create ipfsStorage
- else
- log_message "Volume ipfsStorage exists."
- fi
- # Ensure correct file permissions for /mnt/ipfsStorage
- log_message "Ensuring correct file permissions for /mnt/ipfsStorage..."
- sudo chmod -R 700 "$volume_mountpoint"
- sudo chown -R $(id -u):$(id -g) "$volume_mountpoint"
- # Initialize IPFS if not already initialized
- log_message "Checking if IPFS is initialized..."
- if [ ! -f "$volume_mountpoint/config" ]; then
- log_message "IPFS is not initialized. Initializing now..."
- ipfs init --profile server
- else
- log_message "IPFS is already initialized."
- fi
- # Remove the repo.lock file if it exists (to avoid lock conflicts during startup)
- log_message "Checking for repo.lock to avoid conflicts..."
- lock_file="$volume_mountpoint/repo.lock"
- if [ -f "$lock_file" ]; then
- log_message "Removing repo.lock file to avoid conflicts..."
- rm -f "$lock_file"
- fi
- # Configure IPFS API and Gateway to listen on 0.0.0.0
- log_message "Configuring IPFS API and Gateway to listen on 0.0.0.0..."
- ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001
- ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080
- # Start the IPFS daemon in the background
- log_message "Starting the IPFS daemon..."
- ipfs daemon &
- # Start the PHP built-in server on port 8000
- log_message "#Give the little birdie a drink, or it'll croak!."
- cp "$HOST_DOCKERFILE_PATH" "$CONTAINER_HOME_DOCKERFILE"
- cp "$HOST_START_SH_PATH" "$CONTAINER_HOME_STARTUP"
- log_message "#Starting the PHP server on port 8000 ... Startup process complete."
- cp "$HOST_LOG_PATH" "$CONTAINER_HOME_LOG"
- #Remove the host log file
- rm -f "$HOST_LOG_PATH"
- php -S 0.0.0.0:8000 -t /var/www/html
- Script: start.sh
- #!/bin/bash
- #update: 36161998
- HOST_DOCKERFILE_PATH="$(pwd)/Dockerfile"
- HOST_START_SH_PATH="$(pwd)/start.sh"
- HOST_LOG_PATH="$(pwd)/startup_log.txt"
- CONTAINER_HOME_DOCKERFILE="/home/Dockerfile"
- CONTAINER_HOME_STARTUP="/home/start.sh"
- CONTAINER_HOME_LOG="/home/startup_log.txt"
- # Function to write logs to both the host log file and standard output
- log_message() {
- echo "$1" | tee -a "$HOST_LOG_PATH"
- }
- # Check if the volume ipfsStorage exists
- log_message "Checking if volume ipfsStorage exists..."
- if ! docker volume inspect ipfsStorage > /dev/null 2>&1; then
- log_message "Volume ipfsStorage does not exist. Creating it now..."
- docker volume create ipfsStorage
- else
- log_message "Volume ipfsStorage exists."
- fi
- # Ensure correct file permissions for /mnt/ipfsStorage
- log_message "Ensuring correct file permissions for /mnt/ipfsStorage..."
- sudo chmod -R 700 "$volume_mountpoint"
- sudo chown -R $(id -u):$(id -g) "$volume_mountpoint"
- # Initialize IPFS if not already initialized
- log_message "Checking if IPFS is initialized..."
- if [ ! -f "$volume_mountpoint/config" ]; then
- log_message "IPFS is not initialized. Initializing now..."
- ipfs init --profile server
- else
- log_message "IPFS is already initialized."
- fi
- # Remove the repo.lock file if it exists (to avoid lock conflicts during startup)
- log_message "Checking for repo.lock to avoid conflicts..."
- lock_file="$volume_mountpoint/repo.lock"
- if [ -f "$lock_file" ]; then
- log_message "Removing repo.lock file to avoid conflicts..."
- rm -f "$lock_file"
- fi
- # Configure IPFS API and Gateway to listen on 0.0.0.0
- log_message "Configuring IPFS API and Gateway to listen on 0.0.0.0..."
- ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001
- ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080
- # Start the IPFS daemon in the background
- log_message "Starting the IPFS daemon..."
- ipfs daemon &
- # Start the PHP built-in server on port 8000
- log_message "#Give the little birdie a drink, or it'll croak!."
- cp "$HOST_DOCKERFILE_PATH" "$CONTAINER_HOME_DOCKERFILE"
- cp "$HOST_START_SH_PATH" "$CONTAINER_HOME_STARTUP"
- log_message "#Starting the PHP server on port 8000 ... Startup process complete."
- cp "$HOST_LOG_PATH" "$CONTAINER_HOME_LOG"
- #Remove the host log file
- rm -f "$HOST_LOG_PATH"
- php -S 0.0.0.0:8000 -t /var/www/html
Advertisement
Add Comment
Please, Sign In to add comment