help.Installing lxc with a script prompts an error“Internet NOT Connected“

bluebaby21

New Member
Oct 25, 2022
1
0
1
sscrip:bash -c "$(wget -qLO - https://github.com/teck/Proxmox/raw/main/ct/docker-v4.sh)"

+ start_script
+ whiptail --title SETTINGS --yesno 'Use Default Settings?' --no-button Advanced 10 58
+ header_info
+ echo -e '\033[36m
____ __
/ __ \____ _____/ /_v4__ _____
/ / / / __ \/ ___/ //_/ _ \/ ___/
/ /_/ / /_/ / /__/ ,< / __/ /
/_____/\____/\___/_/|_|\___/_/
\033[m'

____ __
/ __ \____ _____/ /_v4__ _____
/ / / / __ \/ ___/ //_/ _ \/ ___/
/ /_/ / /_/ / /__/ ,< / __/ /
/_____/\____/\___/_/|_|\___/_/

+ echo -e '\033[36mUsing Default Settings\033[m'
Using Default Settings
+ default_settings
+ echo -e '\033[32mUsing Container Type: \033[4;92mUnprivileged\033[m \033[01;31mNO DEVICE PASSTHROUGH\033[m'
Using Container Type: Unprivileged NO DEVICE PASSTHROUGH
+ CT_TYPE=1
+ echo -e '\033[32mUsing Root Password: \033[4;92mAutomatic Login\033[m'
Using Root Password: Automatic Login
+ PW=
+ echo -e '\033[32mUsing Container ID: \033[4;92m108\033[m'
Using Container ID: 108
+ CT_ID=108
+ echo -e '\033[32mUsing Hostname: \033[4;92mdocker\033[m'
Using Hostname: docker
+ HN=docker
+ echo -e '\033[32mUsing Disk Size: \033[4;92m4\033[m\033[32mGB\033[m'
Using Disk Size: 4GB
+ DISK_SIZE=4
+ echo -e '\033[32mAllocated Cores \033[4;92m2\033[m'
Allocated Cores 2
+ CORE_COUNT=2
+ echo -e '\033[32mAllocated Ram \033[4;92m2048\033[m'
Allocated Ram 2048
+ RAM_SIZE=2048
+ echo -e '\033[32mUsing Bridge: \033[4;92mvmbr0\033[m'
Using Bridge: vmbr0
+ BRG=vmbr0
+ echo -e '\033[32mUsing Static IP Address: \033[4;92mdhcp\033[m'
Using Static IP Address: dhcp
+ NET=dhcp
+ echo -e '\033[32mUsing Gateway Address: \033[4;92mDefault\033[m'
Using Gateway Address: Default
+ GATE=
+ echo -e '\033[32mUsing MAC Address: \033[4;92mDefault\033[m'
Using MAC Address: Default
+ MAC=
+ echo -e '\033[32mUsing VLAN Tag: \033[4;92mDefault\033[m'
Using VLAN Tag: Default
+ VLAN=
+ echo -e '\033[36mCreating a Docker LXC using the above default settings\033[m'
Creating a Docker LXC using the above default settings
+ '[' 1 == 1 ']'
+ FEATURES=nesting=1,keyctl=1
++ mktemp -d
+ TEMP_DIR=/tmp/tmp.C7IokQj1cr
+ pushd /tmp/tmp.C7IokQj1cr
+ export CTID=108
+ CTID=108
+ export PCT_OSTYPE=debian
+ PCT_OSTYPE=debian
+ export PCT_OSVERSION=11
+ PCT_OSVERSION=11
+ export PCT_DISK_SIZE=4
+ PCT_DISK_SIZE=4
+ export 'PCT_OPTIONS=
-features nesting=1,keyctl=1
-hostname docker
-net0 name=eth0,bridge=vmbr0,ip=dhcp
-onboot 1
-cores 2
-memory 2048
-unprivileged 1

'
+ PCT_OPTIONS='
-features nesting=1,keyctl=1
-hostname docker
-net0 name=eth0,bridge=vmbr0,ip=dhcp
-onboot 1
-cores 2
-memory 2048
-unprivileged 1

'
++ wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh
+ bash -c '#!/usr/bin/env bash
YW=`echo "\033[33m"`
BL=`echo "\033[36m"`
RD=`echo "\033[01;31m"`
GN=`echo "\033[1;92m"`
CL=`echo "\033[m"`
CM="${GN}✓${CL}"
CROSS="${RD}✗${CL}"
BFR="\\r\\033[K"
HOLD="-"

function msg_info() {
local msg="$1"
echo -ne " ${HOLD} ${YW}${msg}..."
}

function msg_ok() {
local msg="$1"
echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
}
function msg_error() {
local msg="$1"
echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
}

msg_info "Validating Storage"
VALIDCT=$(pvesm status -content rootdir | awk '\''NR>1'\'')
if [ -z "$VALIDCT" ]; then msg_error "Unable to detect a valid Container Storage location."; exit 1; fi;
VALIDTMP=$(pvesm status -content vztmpl | awk '\''NR>1'\'')
if [ -z "$VALIDTMP" ]; then msg_error "Unable to detect a valid Template Storage location."; exit 1; fi;

set -o errexit
set -o errtrace
set -o nounset
set -o pipefail
shopt -s expand_aliases
alias die='\''EXIT=$? LINE=$LINENO error_exit'\''
trap die ERR

function error_exit() {
trap - ERR
local reason="Unknown failure occurred."
local msg="${1:-$reason}"
local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE"
echo -e "$flag $msg" 1>&2
exit $EXIT
}

function select_storage() {
local CLASS=$1
local CONTENT
local CONTENT_LABEL
case $CLASS in
container) CONTENT='\''rootdir'\''; CONTENT_LABEL='\''Container'\'';;
template) CONTENT='\''vztmpl'\''; CONTENT_LABEL='\''Container template'\'';;
*) false || die "Invalid storage class.";;
esac

local -a MENU
while read -r line; do
local TAG=$(echo $line | awk '\''{print $1}'\'')
local TYPE=$(echo $line | awk '\''{printf "%-10s", $2}'\'')
local FREE=$(echo $line | numfmt --field 4-6 --from-unit=K --to=iec --format %.2f | awk '\''{printf( "%9sB", $6)}'\'')
local ITEM=" Type: $TYPE Free: $FREE "
local OFFSET=2
if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then
local MSG_MAX_LENGTH=$((${#ITEM} + $OFFSET))
fi
MENU+=( "$TAG" "$ITEM" "OFF" )
done < <(pvesm status -content $CONTENT | awk '\''NR>1'\'')

if [ $((${#MENU[@]}/3)) -eq 1 ]; then
printf ${MENU[0]}
else
local STORAGE
while [ -z "${STORAGE:+x}" ]; do
STORAGE=$(whiptail --title "Storage Pools" --radiolist \
"Which storage pool you would like to use for the ${CONTENT_LABEL,,}?\n\n" \
16 $(($MSG_MAX_LENGTH + 23)) 6 \
"${MENU[@]}" 3>&1 1>&2 2>&3) || die "Menu aborted."
done
printf $STORAGE
fi
}

[[ "${CTID:-}" ]] || die "You need to set '\''CTID'\'' variable."
[[ "${PCT_OSTYPE:-}" ]] || die "You need to set '\''PCT_OSTYPE'\'' variable."

[ "$CTID" -ge "100" ] || die "ID cannot be less than 100."

if pct status $CTID &>/dev/null; then
echo -e "ID '\''$CTID'\'' is already in use."
unset CTID
die "Cannot use ID that is already in use."
fi

TEMPLATE_STORAGE=$(select_storage template) || exit
msg_ok "Using ${BL}$TEMPLATE_STORAGE${CL} ${GN}for Template Storage."

CONTAINER_STORAGE=$(select_storage container) || exit
msg_ok "Using ${BL}$CONTAINER_STORAGE${CL} ${GN}for Container Storage."

msg_info "Updating LXC Template List"
pveam update >/dev/null
msg_ok "Updated LXC Template List"

TEMPLATE_SEARCH=${PCT_OSTYPE}-${PCT_OSVERSION:-}
mapfile -t TEMPLATES < <(pveam available -section system | sed -n "s/.*\($TEMPLATE_SEARCH.*\)/\1/p" | sort -t - -k 2 -V)
[ ${#TEMPLATES[@]} -gt 0 ] || die "Unable to find a template when searching for '\''$TEMPLATE_SEARCH'\''."
TEMPLATE="${TEMPLATES[-1]}"

if ! pveam list $TEMPLATE_STORAGE | grep -q $TEMPLATE; then
msg_info "Downloading LXC Template"
pveam download $TEMPLATE_STORAGE $TEMPLATE >/dev/null ||
die "A problem occured while downloading the LXC template."
msg_ok "Downloaded LXC Template"
fi

DEFAULT_PCT_OPTIONS=(
-arch $(dpkg --print-architecture))

PCT_OPTIONS=( ${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}} )
[[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=( -rootfs $CONTAINER_STORAGE:${PCT_DISK_SIZE:-8} )

msg_info "Creating LXC Container"
pct create $CTID ${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE} ${PCT_OPTIONS[@]} >/dev/null ||
die "A problem occured while trying to create container."
msg_ok "LXC Container ${BL}$CTID${CL} ${GN}was successfully created."'
✓ Using local for Template Storage.
✓ Using local-lvm for Container Storage.
✓ Updated LXC Template List
✓ LXC Container 108 was successfully created.
+ LXC_CONFIG=/etc/pve/lxc/108.conf
+ cat
+ msg_info 'Starting LXC Container'
+ local 'msg=Starting LXC Container'
+ echo -ne ' - \033[33mStarting LXC Container...'
- Starting LXC Container...+ pct start 108
+ msg_ok 'Started LXC Container'
+ local 'msg=Started LXC Container'
+ echo -e '\r\033[K \033[1;92m✓\033[m \033[1;92mStarted LXC Container\033[m'
✓ Started LXC Container
++ wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/setup/docker-install.sh
+ lxc-attach -n 108 -- bash -c '#!/usr/bin/env bash
YW=`echo "\033[33m"`
RD=`echo "\033[01;31m"`
BL=`echo "\033[36m"`
GN=`echo "\033[1;92m"`
CL=`echo "\033[m"`
RETRY_NUM=10
RETRY_EVERY=3
NUM=$RETRY_NUM
CM="${GN}✓${CL}"
CROSS="${RD}✗${CL}"
BFR="\\r\\033[K"
HOLD="-"
set -o errexit
set -o errtrace
set -o nounset
set -o pipefail
shopt -s expand_aliases
alias die='\''EXIT=$? LINE=$LINENO error_exit'\''
trap die ERR

function error_exit() {
trap - ERR
local reason="Unknown failure occurred."
local msg="${1:-$reason}"
local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE"
echo -e "$flag $msg" 1>&2
exit $EXIT
}

function msg_info() {
local msg="$1"
echo -ne " ${HOLD} ${YW}${msg}..."
}

function msg_ok() {
local msg="$1"
echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
}

function msg_error() {
local msg="$1"
echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
}

msg_info "Setting up Container OS "
sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen
locale-gen >/dev/null
while [ "$(hostname -I)" = "" ]; do
1>&2 echo -en "${CROSS}${RD} No Network! "
sleep $RETRY_EVERY
((NUM--))
if [ $NUM -eq 0 ]
then
1>&2 echo -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}"
exit 1
fi
done
msg_ok "Set up Container OS"
msg_ok "Network Connected: ${BL}$(hostname -I)"

set +e
alias die='\'''\''
if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else msg_error "Internet NOT Connected"; exit 1; fi;
RESOLVEDIP=$(nslookup "github.com" | awk -F'\'':'\'' '\''/^Address: / { matched = 1 } matched { print $2}'\'' | xargs)
if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi;
alias die='\''EXIT=$? LINE=$LINENO error_exit'\''
set -e

msg_info "Updating Container OS"
apt-get update &>/dev/null
apt-get -y upgrade &>/dev/null
msg_ok "Updated Container OS"

msg_info "Installing Dependencies"
apt-get install -y curl &>/dev/null
apt-get install -y sudo &>/dev/null
msg_ok "Installed Dependencies"

get_latest_release() {
curl -sL https://api.github.com/repos/$1/releases/latest | grep '\''"tag_name":'\'' | cut -d'\''"'\'' -f4
}

DOCKER_LATEST_VERSION=$(get_latest_release "moby/moby")
PORTAINER_LATEST_VERSION=$(get_latest_release "portainer/portainer")
DOCKER_COMPOSE_LATEST_VERSION=$(get_latest_release "docker/compose")

msg_info "Installing Docker $DOCKER_LATEST_VERSION"
DOCKER_CONFIG_PATH='\''/etc/docker/daemon.json'\''
mkdir -p $(dirname $DOCKER_CONFIG_PATH)
cat >$DOCKER_CONFIG_PATH <<'\''EOF'\''
{
"log-driver": "journald"
}
EOF
sh <(curl -sSL https://get.docker.com) &>/dev/null
msg_ok "Installed Docker $DOCKER_LATEST_VERSION"

read -r -p "Would you like to add Portainer? <y/N> " prompt
if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]
then
PORTAINER="Y"
else
PORTAINER="N"
fi

if [[ $PORTAINER == "Y" ]]; then
msg_info "Installing Portainer $PORTAINER_LATEST_VERSION"
docker volume create portainer_data >/dev/null
docker run -d \
-p 8000:8000 \
-p 9000:9000 \
--name=portainer \
--restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v portainer_data:/data \
portainer/portainer-ce:latest &>/dev/null
msg_ok "Installed Portainer $PORTAINER_LATEST_VERSION"
fi

read -r -p "Would you like to add Docker Compose? <y/N> " prompt
if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]
then
DOCKER_COMPOSE="Y"
else
DOCKER_COMPOSE="N"
fi

if [[ $DOCKER_COMPOSE == "Y" ]]; then
msg_info "Installing Docker Compose $DOCKER_COMPOSE_LATEST_VERSION"
DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
mkdir -p $DOCKER_CONFIG/cli-plugins
curl -sSL https://github.com/docker/compose/r...SE_LATEST_VERSION/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose
chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose
msg_ok "Installed Docker Compose $DOCKER_COMPOSE_LATEST_VERSION"
fi

PASS=$(grep -w "root" /etc/shadow | cut -b6);
if [[ $PASS != $ ]]; then
msg_info "Customizing Container"
rm /etc/motd
rm /etc/update-motd.d/10-uname
touch ~/.hushlogin
GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf"
mkdir -p $(dirname $GETTY_OVERRIDE)
cat << EOF > $GETTY_OVERRIDE
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM
EOF
systemctl daemon-reload
systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed '\''s/\.d//'\'')
msg_ok "Customized Container"
fi

msg_info "Cleaning up"
apt-get autoremove >/dev/null
apt-get autoclean >/dev/null
msg_ok "Cleaned"'
✓ Set up Container OS
✓ Network Connected: 192.168.31.218
✗ Internet NOT Connected
+ exit
root@pve:~#
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!